Solved

Find URL of parent window?

Posted on 1998-11-14
7
398 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

739 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