Solved

Find URL of parent window?

Posted on 1998-11-14
7
395 Views
Last Modified: 2008-01-16
From a browser window (NS | IE) I open a popup window. On the popup window I would like to provide a button that displays the URL of the parent window in an alert box.

I have tried the opener property (in NS), but there are some security issues. It doesnt seem to work in IE.

Thanks,

-unmesh.
0
Comment
Question by:unmeshm
7 Comments
 
LVL 10

Accepted Solution

by:
kollegov earned 50 total points
ID: 1273991
Wouldn't it be easier to pass it as parameter?
window.open("some.html?"+escape(document.location+""),"pop","width=....");

So you can retreive it in pop-up window script like this:
parentloc=unescape(document.location.search+"");

Note this wouldn't work in MIE3
as it don't support 'searach' property.
0
 
LVL 4

Expert Comment

by:martinag
ID: 1273992
Note that it should be
if (self.location && location.length() != 0)
  parentloc = unescape(location.search.substring(1));

Martin
0
 
LVL 4

Expert Comment

by:martinag
ID: 1273993
Sorry,
if (self.location && location.length() != 0)
should be
if (location.search && location.search.length() != 0)

Martin
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:unmeshm
ID: 1273994
Thanks for your response.

I am not sure this will work if the URL on the browser window
that launched the popup changes. Here's a scenario.

1. on a browser window displaying http://url1 I launch a popup
2. on this popup I click on a button to display the URL of the
   browser window (this would now display http://url1)
3. NOW, on the browser window I visit another site such that the
   URL of the browser window is now http://url2
4. NOW, when I click on the button on the popup, I expect to see
   http://url2 to be displayed

Am not sure if the solution you provided will report changing
URL's on the main browser window.

Thanks.
0
 
LVL 10

Expert Comment

by:kollegov
ID: 1273995
This will work until both are at the same domain
(in MI4, NN3, NN4)
If there are at the different domains, than security manager will disable access from one window to other one.

Very reasonable thing, BTW, otherwize if you go to other site which have forms, pop-up can steal the form content if left floating. Also URL can contain info in querry string, and
your script will be able to steal this data.
So if someone will find way to do what you need this would mean
that one more security hole found and it will be patched
in next releases of browsers.


The only what can be done is implemented in
script below. At least this one don't give errors
when access restricted.
This is script for pop-up window.

<html><head>
<script>
var mess="Can't monitor location at other domain."
function doit()
{if(opener)
  {if(!opener.closed)
   {if(opener.eval)
     {l=opener.eval("document.location+''");}
    else
     {l=mess}
    if(l.indexOf("[")==0)
     {l=mess}
    document.f.ff.value=l;
    setTimeout("doit()",200);
   }
  }
}
</script>



</head>
<body onload="doit()">
<form name="f">
 <input type=text name="ff" size=50>
</form>
</body>
</html>
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1273996
Kollegov: IE3 DOES support the search property as long as the file is loaded from the internet and not harddisk.
0
 
LVL 10

Expert Comment

by:kollegov
ID: 1273997
Thanks Michele :) I'll try to find MIE3 to test this :)

0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question