<script language=javascript>
function name(name) {
var name;
window.opener.document.getElementById('school_name').value = name;
}
</script>
2.子視窗傳值呼叫母視窗函式
<script language=javascript>
function name(name) {
window.opener.outside(name);//標紅字體則為母視窗的javascript的函式
}
</script>
------------------------------------------------------------------------------------------------
testopener.html:
<script language="JavaScript" type="text/javascript">
var subwinId;
function openTest() {
subwinId = window.open('testSub.html?msg=hi');
}
function sendValueToParent() {
var s = subwinId.document.getElementById("submsg");
s.innerHTML = "Done!";
}
function reloadSubWindow() {
subwinId.reloadSubWindow();
}
function closeSubWindow() {
subwinId.close();
}
</script>
</head>
<body >
<input type="button" id="checkButton" value="送出" onclick="openTest()">
<br/>
<input type="button" id="sendButton" value="送值給子視窗" onclick="sendValueToParent()">
<br/>
<input type="button" id="sendButton" value="reload子視窗" onclick="reloadSubWindow()">
<br/>
<input type="button" id="sendButton" value="關閉子視窗" onclick="closeSubWindow()">
<br/>
回傳值:<div id="parentMessageId"></div>
</body>
testSub.html:
<script language="JavaScript" type="text/javascript">
$(document).ready(function(){
var msg = Request["msg"];
$("#submsg").text(msg);
alert("reloadSubWindow");
});
var url=location.search;
var Request = new Object();
if(url.indexOf("?")!=-1)
{
var str = url.substr(1) //去掉?號
strs = str.split("&");
for(var i=0;i<strs.length;i++)
{
Request[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
function reloadSubWindow(){
location.reload();
}
</script>
</head>
<body >
<div id="submsg"></div>
</body>
參考網址:
http://tc.wangchao.net.cn/bbs/detail_553964.html
http://crazy.molerat.net/learner/cpuroom/homepage/reading.php?filename=97102215523.dov
沒有留言:
張貼留言