Solved

Find URL of parent window?

Posted on 1998-11-14
7
391 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now