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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with onUnload 1

Status
Not open for further replies.

Stewart531

Programmer
Feb 18, 2003
36
US
I'm having a problem calling an onUnload function from the <body> portion of my framestring. It causes the code in the <frameset> to not work. I know the <frameset> part is fine, because it works when I remove the <body> code. Here is my code:

NFW = window.open(&quot;&quot;,&quot;mytarget1&quot;,windowprops)

var frameString=&quot;&quot;+
&quot;<html>&quot;+
&quot;<head>&quot;+
&quot;<title>&quot;+title+&quot;</title>&quot;+
&quot;<body onunload=alert(\&quot;Test!\&quot;);>&quot; +
&quot;</body>&quot; +
&quot;</head>&quot;+
&quot;<frameset rows='*,0' framespacing=0 border=0 frameborder=0>&quot;+
&quot;<frame name='top' src='&quot;+URLpop+&quot;' scrolling=auto>&quot;+
&quot;<frame name='bottom' src='SEL' scrolling='no'>&quot;+
&quot;</frameset>&quot;+
&quot;</html>&quot;

NFW.document.open();
NFW.document.write(frameString)
NFW.document.close()


Can I not use both <body> and <frameset> at once?

Thanks,
Stewart
 
all attribute values should be surrounded in quotes.

what you want to end up with is this:
<body onunload=&quot;alert('Test!');&quot;>

so your js should look like this:
&quot;<body onunload=\&quot;alert('Test!');\&quot;>&quot; +


=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Ok, that works and I get the alert. However, when I put that in, the <framestring> part doesn't work, and the document whose path is contained in &quot;URLpop&quot; is not opened in the window. The only time the document is opened in the window is when I remove the <body> part. Also, I don't receive any errors when I use both the <body> and <framestring>. Any idea why that happens?

Thanks,
Stewart
 
Well, I resolved one of my issues. If I remove the <body> part and use:

&quot;<frameset onunload=\&quot;alert('Test');\&quot;>&quot;

it now works.

Now I have a new problem. Instead of doing an alert() function, I want to use a user defined function. For example, this will not work:

&quot;<frameset onunload=\&quot;CallAlert();\&quot;>&quot; +
&quot;<script type=\&quot;text/JavaScript\&quot;>&quot; +
&quot;function CallAlert(){&quot; +
&quot;alert('Test') &quot; +
&quot;}&quot; +
&quot;</script>&quot; +

While this worked when it was <body onunload....>, it no longer works. Any ideas?

Thanks,
Stewart
 
i don't think you can have a <script> block inside a frameset - try putting the <script> block before the <frameset>, and escape the slash in </script>


&quot;<script type=\&quot;text/JavaScript\&quot;>&quot; +
&quot;function CallAlert(){&quot; +
&quot;alert('Test') &quot; +
&quot;}&quot; +
&quot;<\/script>&quot; +
&quot;<frameset onunload=\&quot;CallAlert();\&quot;>&quot; +
...

=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Thanks Jeff, that worked perfectly! I appreciate all of your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top