Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Find URL of parent window?

Posted on 1998-11-14
7
Medium Priority
?
403 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 200 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…
Suggested Courses

926 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