Click to See Complete Forum and Search --> : Best way to create a complex pop-up window?


jrlamar
05-12-2003, 12:42 PM
OK, here's the situation ...

From a static HTML page, I'm calling a Perl script in a pop-up window (via JavaScript) that I've customized to provide an "e-mailable version" of the HTML content. The trick is that the pop-up window has to have information that varies from page to page (specifically, the URL, the title, and the root server path to the page). Previously, I've hand-coded each page individually ... which is a major pain in the neck, of course.

So my question is: How can I create a pop-up window that automatically pulls in the necessary information from the parent window -- that is, the information inside the <title> tags as well as the document name (example.html) -- which I can then drop into tags in this pop-up window? In other words, I want to pass parent window variables into the pop-up window HTML code like this ...

<input type=HIDDEN name="pagetosend" value="/root/path/to/example.html">
<input type=HIDDEN name="pagename" value="Example Page Title">
<input type=HIDDEN name="pageurl" value="http://www.123.com/example.html">

What's the best way (or ANY way) to accomplish this? Help!



Thanks,

Jason

Jona
05-12-2003, 12:49 PM
<script>
function getInfo(){
alert(parent.document.formName.pagetosend.value);
alert(parent.document.title);
}
</script>

<body onload="getInfo()">

A1ien51
05-12-2003, 12:49 PM
You can document.write to the window....

jrlamar
05-12-2003, 01:52 PM
Jona,

Excellent ... yet how do I implement this? I assume the code you provided needs to be placed in the pop-up window, right? But where do these variables come into play? Don't I have to repeat the parent.document calls in the hidden form tags somehow? Also, while I understand the parent.document.title aspect, does the parent.document.formName.pagetosend.value actually pull in the URL from the parent window? Or am I missing a step somewhere?

Can you give me more information about this? If you could just write out some sample code for the pop-up window, based on the example I gave above, that would be extremely helpful ... so I can understand how this is working.



Thanks again,

Jason

jrlamar
05-12-2003, 01:55 PM
Also, let me clarify: I would like to have ONE pop-up window serve as a "template" e-mail version page for my ENTIRE Web site. As it stands, I have static HTML files and pop-up e-mail version files on a one-to-one basis. I'm just trying to consolidate all the work and save myself some major headaches.

Jason

Jona
05-12-2003, 02:13 PM
In the popup window:

<html><head><script>
function getInfo(){
document.write("<b>"+opener.document.title+"</b><br>");
document.write("\nThe page to send: "+opener.document.formName.pagetosend.value);
document.write("\nThe URL of the parent: "+opener.location);
}
</script></head>
<body>
<p>Your information, blah blah, blah...</p>
<p>
<script language="javascript" type="text/javascript">
getInfo();
</script></p>
</body></html>

jrlamar
05-12-2003, 02:43 PM
Sorry, I should have just included my original pop-up window code to provide a working base. Here's the relevant part of the HTML, which is a form that the visitor can use to e-mail a version of the parent window to somebody ...

<form method=POST>
<input type=HIDDEN name="pagetosend" value="/var/www/htdocs/folder/example.html">
<input type=HIDDEN name="pagename" value="Example Title">
<input type=HIDDEN name="pageurl" value="http://www.mysite.com/example.html"></form>

So could the document.write functions then be embedded as ...

<script>
function info1(){
document.write("/var/www/htdocs/folder/"+opener.document.formName.pagetosend.value);
}
</script>

<script>
function info2(){
document.write(opener.document.title);
}
</script>

<script>
function info3(){
document.write(opener.location);
}
</script>

</head><body>

<form method=POST>
<input type=HIDDEN name="pagetosend" value="javascript:info1()">
<input type=HIDDEN name="pagename" value="javascript:info2()">
<input type=HIDDEN name="pageurl" value="javascript:info3()"></form>



Or is there a better way to do this?

Jason

Jona
05-12-2003, 02:48 PM
This is recalling the same part of itself. You should never use Javascript:function() in anything except for a link.

jrlamar
05-12-2003, 02:59 PM
OK ... so how should I do this? Can I call the document.write functions directly from within the form? Again, these are all hidden variables that need to be pulled from the parent window to make the Perl e-mail script work. I don't actually need to display any of this information, which is what the example that you gave -- the getInfo() function -- looks like it's doing.

Jason

Jona
05-12-2003, 03:13 PM
In that case, use this:

<script>
function setVars(){
document.forms[0].pagetosend.value="/var/www/htdocs/folder/"+opener.document.formName.pagetosend.value;
document.forms[0].pagename.value=opener.document.title;
document.forms[0].pageurl.value=opener.location;
}
</script>
</head><body onload="setVars()">
<form method=POST>
<input type=HIDDEN name="pagetosend">
<input type=HIDDEN name="pagename">
<input type=HIDDEN name="pageurl"></form>

jrlamar
05-15-2003, 02:18 PM
Jona,

I tried the code you provided, and while the Perl script is working, it's just outputting empty values in the e-mail messages I send to myself. Plus, the Web browser (IE) gets stuck in a processing loop on the form page, so I have to manually close the browser window to stop my spinning mouse cursor.

Do I need to append some sort of value="x" tag to these lines as well? ...

<input type=HIDDEN name="pagetosend">
<input type=HIDDEN name="pagename">
<input type=HIDDEN name="pageurl">




Thanks again,

Jason

Jona
05-15-2003, 02:19 PM
LOL, of course. Add a value attribute to the hidden fields! lol

jrlamar
05-15-2003, 02:28 PM
Riiiiiiiight ... so what would that be, exactly? I'm afraid I have very little experience dropping dynamically generated JavaScript content into forms, which is why I'm posting to this forum. I've tried all these variations without success:

<input type=HIDDEN name="pagetosend" value="">
<input type=HIDDEN name="pagename" value="">
<input type=HIDDEN name="pageurl" value="">

<input type=HIDDEN name="pagetosend" value="pagetosend">
<input type=HIDDEN name="pagename" value="pagename">
<input type=HIDDEN name="pageurl" value="pageurl">

<input type=HIDDEN name="pagetosend" value>
<input type=HIDDEN name="pagename" value>
<input type=HIDDEN name="pageurl" value>

If it works, I assume I should see the proper values displayed in the HTML code as soon as the pop-up window is opened. Yes?

Jason

Jona
05-15-2003, 02:32 PM
The value should be set in Perl. <input type="hidden" name="pagetosend" value="the_page_to_send"> lol It's supposed to be whatever you want the page to send to be. ;)

khalidali63
05-15-2003, 03:59 PM
Just curious did you mean something like this..?

http://68.145.35.86/skills/javascripts/DataTransferToChildFromParentWin.html

Jona
05-15-2003, 04:05 PM
We never know what they want, do we, Khalid? :D