View Full Version : Child and Parent windows

08-01-2002, 03:48 PM
I have a HTML file in a window (Window1) containing a textbox and a button.
The button opens a sized window (Window2) which the user can use to browse to whichever page they want anywhere on the internet.
When they close Window2 I want the last url they visited (i.e. the current url of Window2) to populate the text box on my original page (Window1) .
Can this be done?

Could you give me any pointers?

I would really appreciate any help you could give me.

Mary Hill
Senior Analyst
Sheffield Hallam University

08-01-2002, 04:43 PM
That cannot be done due to the same-origin security policy. You are only allowed to read the URL of files that reside in your domain, everything else is considered an infringe on privacy.

08-01-2002, 04:50 PM
mordred is correct there, but.... if you were tracking on an intranet you could get the location of the child window by polling it.

Try this, it was a proof of concept. Note that it will only show URLS that are on the same server. It updates every second, and has a counter in it, the thought was to time how long the user was at a particular page. It never got off the ground as we convinced them it was not a good idea to spy so blatantly :)

<form name=temp method="post" action="http://www.xmission.com/~tnelson/mirror.php" onSubmit="return validateForm(this)">
<a href="javascript:showSecondWindow()">New Window</a><br>
<input type="text" name="URL" size="50" value=""><br>

<script language="JavaScript">
function showSecondWindow(){

myCount = 0;
function checkPage(){
document.temp.URL.value = myCount + "URL: " + Swin.location;