Forum Moderators: open

Message Too Old, No Replies

onunload event pass value to pop up window?

         

jeremy goodrich

8:24 pm on Mar 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm working on a piece of javascript which is 'supposed' to open a new window, and pass a value to a perl script, which is already working and doing neat and wonderful things.

however, since i don't know anything about javascript, I thought I'd ask for some help :)

this is the stuff that goes on the page calling the script, "myfile.js"

<SCRIPT LANGUAGE="JavaScript" SRC="http*://www.myurl-here/myfile.js"></SCRIPT>

onUnload=doStuff"(varvalue)">

here's the code that the page is calling in the 'onUnload event':

function doStuff(id) {
var sysurl="http*://www.myotherurl-here.com/directory";
var url=(sysurl)+"/redirect.cgi?id="+(id);
var exit=true;
if (exit) {

window.open(url,'openStuff','width=800,height=600,top=5000,left=5000,scrollbars=yes,location=yes,directories=no,
status=yes,menubar=no,toolbar=no,resizable=yes');
}
self.focus();
}

That's about the size of it. What I'm trying to do is pass the value from the javascript 'onUnload' event into the pop up script file, which then opens the new window with the value passed in from the original html file into the perl script...hope that makes sense.

toadhall

12:04 am on Mar 23, 2002 (gmt 0)

10+ Year Member




re: onUnload=doStuff"(varvalue)">

I'm not a Javascript whiz by any means but those double quotes look awfully suspicious.

Also, what is the purpose of the asterisk in the url cited in the function and in the external .js call?

You could add 'screenX=5000', 'screenY=5000' to window.open's attributes for rendering window distance in NN4+.

jeremy goodrich

12:15 am on Mar 23, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



he he, astrisk just in case somebody wanted to copy/paste the urls (they aren't real of course)

just tried it without the quotes...no go.
(good suggestion btw for netscape browsers...after I get it working, I'll attempt that feat :) )

any other ideas?

toadhall

1:09 am on Mar 23, 2002 (gmt 0)

10+ Year Member



The url in window.open must be in quotes (not the variable name, but its contents), so you'll have to add them to the variables sysurl and url as \'.
Then it would end up:
window.open('url/redirect.cgi?id=1','etcetera',...);

... or some such thing.

Anyway, that may help.

jeremy goodrich

1:38 am on Mar 23, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks, but that didn't seem to help either. :(

The script is erroring out on the page as it loads...hm. If I put the url in the window.open, then that defeats the purpose of trying to pass in the value from the html page with the onUnload function...

which value the javascript needs to pass to my perl script, so that my application can work :) he he. (it's almost giving me a headache).

I've got an example that works...but I tried to port it over, and then got stuck with the mess I'm in now.

toadhall

2:05 am on Mar 23, 2002 (gmt 0)

10+ Year Member



This re-tooled version works; it sends the value to the new window appended to the url.

this stuff...


<html>
<head>
<title>Do Stuff</title>
<!--dostuff.html-->
</head>
<body>
<script language="JavaScript">
<!--
var di = "toad";
function doStuff(id) {
var sysurl="otherstuff";
var url=sysurl+".html?id="+id;
window.open(url,'openStuff','width=350,height=150,top=5,left=5,scrollbars=yes,location=yes,directories=no,status=yes,menubar=no,toolbar=no,resizable=yes');
}
//-->
</script>
<form>
<input type=button value="Do Stuff!" onClick=doStuff(di)>
</body>
</html>

...will pop up this 'other stuff'...

<html>
<head>
<title>Other Stuff</title>
<!--otherstuff.html-->
</head>
<body>
Doing other stuff
</body>
</html>

...with this url:
.../otherstuff.html?id=toad

I just altered the Event (onClick) and added the value to the 'di' variable for this purpose.

I really hope I haven't wasted your time and that this will help in some way.

(edited by: toadhall at 2:14 am (utc) on Mar. 23, 2002)

jeremy goodrich

2:13 am on Mar 23, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



that looks pretty good, going to try your solution in the morning (about to leave the office)

I really appreciate the help :) Javascript is something I haven't ever done anything with (except copy/paste, lol.)