Solved

Find URL of parent window?

Posted on 1998-11-14
7
394 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

777 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