Click to See Complete Forum and Search --> : Problems with window running a function in its opener
karayan
07-24-2003, 07:42 PM
This only happens in NS, not IE. I have a script in window 1 whch opens window 2. Window 2 has a link like so:
<a href='#top' onClick='opener.blabla()'>Click here</a>
the idea is, when the user clicks the link, function blabla() in window 1 runs (and does things in that window). In IE this works fine. But in Netscape, the function runs fine in window 1, but window 2 loads the HTML file of window 1 also!!!!!!!
It seems to me that the behavior in window 2 should be: 1) run the function, 2) go to anchor 'top' in the file that is already loaded in window 2. WHy does it load the file of window 1 and how do I stop that?
Thanks.
Khalid Ali
07-24-2003, 08:39 PM
use
top.opener.blah()
or better if u can post a link to the page in question
karayan
07-24-2003, 09:05 PM
The top.opener.... did not do the trick. It's not that it does notfind the correct window object. It finds it, becuase the function (which is in window 1) runs fine. It's what it does AFTER that: Window 2 loads the document that was in Window 1.
Here is the code in window 2:
<body bgcolor='#dddddd'>
<a name='top'></a>
<font color='#007700'><b>Select by clicking below:</b></font><br>
<table border=0><tr>
<td valign='top'><a href='#top' onClick='top.opener.AWS_flip(0)'><IMG height=200 src="image1.jpg" width=200 border=0></a></td>
<td valign='top'><a href='#top' onClick='top.opener.AWS_flip(1)'><IMG height=100 src="image2.jpg" width=300 border=0></a></td>
<td valign='top'><a href='#top' onClick='top.opener.AWS_flip(2)'><IMG height=300 src="image3.jpg" width=300 border=0></a></td>
</tr></table>
</body>
Sorry this is so ugly. The code is actually machine-generated and I just cut-and-pasted the source view. Ugly.
The AWS_flip() calls are executed correctly. But then, window 2 goes and loads the document from window 1. I guess this is because of the href spec in the links above. But if I removed the href, NS doesn't treat those links as links anymore
:rolleyes:
So, what can I do to those links so they still run the function, but no cause any loading of anything in window 2?
And again, this is only in NS. IE behaves correctly. :D
This worked fine for me in NN, Mozilla, and IE:
<script type="text/javascript">
newwin = window.open("","","width=400,height=300");
newwin.document.write('<a href="#" onclick="window.opener.someFunction(); return false;">Run</a>');
function someFunction() {
document.write ("This works fine.");
}
</script>
karayan
07-24-2003, 09:49 PM
It worked!!
It's the "return false;" statement you added to the onClick handler that did it!
Thanks!:D
Yes, return false tells the browser not to run whatever is in the links href...