Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to call functions in opener window.

Status
Not open for further replies.

lovekang

Programmer
Feb 16, 2006
86
KR
<html>
<script>
function MyFunc(){
alert("MyFunction");
}

function DoPopup(){
var oPopup = window.createPopup();
var oPopupBody = oPopup.document.body;
oPopupBody.innerHTML = "<input type=button value='Hello' onmouseover='opener.MyFunc();'>";
oPopup.show(10, 10, 200, 100);
}
</script>
<input type=button value=" Create Popup " onclick="DoPopup();">
</html>
 
Is all the above code on the same page? Are you trying to call a function called MyFunc from oPopup, or a function called MyFunc from the window that opened the page above?

If you are trying to get oPopup to call the MyFunc function in the page above, then what you have should work.

If it doesn't, perhaps you could give us some more to go on - like any error messages, etc you have (install Firefox, and look in the JavaScript console).

All this, of course, assumes that your popup is being created - the "createPopup" call is invalid unless you've coded it somewhere. Try using "window.open" instead if you haven't.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Use window.open() instead of createPopup() at least for broader support. But the main thing is createPopup() seems behaving buggy even in ie other than earlier release. This is how to make it cross browser. There is an implementation where permission denied issue is resolved properly.
[tt]
<html>
<head>
<script>
function MyFunc(){
alert("MyFunction");
}

function DoPopup(){
var oPopup = window.open("","","left=10px, top=10px, width=200px, height=100px, menubar=no, titlebar=no, status=no, toolbar=no");
oPopup.document.open()
oPopup.document.write ("<button onmouseover='window.opener.MyFunc();'>Hello</botton>");
oPopup.document.close()
}
</script>
</head>
<body>
<button onclick="DoPopup();">Create Popup</button>
</body>
</html>
[/tt]
ps. Note that you do not use input button without a form as a matter of concept. Even ie documentation's example does not use it, it use simple button which is a the correct way.
 

Thanks all.

I just found "parent".

the code below is the working solution. thanks.


<html>
<script>
function MyFunc(){
alert("MyFunction");
}

function DoPopup(){
var oPopup = window.createPopup();
var oPopupBody = oPopup.document.body;
oPopupBody.innerHTML = "<input type=button value='Hello' onmouseover='parent.MyFunc();'>";
oPopup.show(10, 10, 200, 100);
}
</script>
<input type=button value=" Create Popup " onclick="DoPopup();">
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top