View Full Version : value of window.opener.location
Horus_Kol
11-19-2004, 10:26 AM
Okay, so I have this:
if (this.opener.location)
url_opener = this.opener.location;
else
url_opener = "outside";
document.getElementById("test").innerHTML = "url=" + url_opener + "...";
document.title = url_opener;
it correctly prints the location while I am within my intranet, but as soon as the person navigates out to somewhere else, there doesn't seem to be a value for this.opener.location - but i can't get it to recognise, and just a javascript error in this case...
I have tried isNull and isEmpty on this, and still get javascript errors...
how do i do this?
IKLOP
11-19-2004, 11:17 AM
maybe try thisif (window.opener)
url_opener = window.opener.location.href;
else
url_opener = "outside";
document.getElementById("test").innerHTML = "url=" + url_opener + "...";
document.title = url_opener;
Horus_Kol
11-19-2004, 11:32 AM
no improvement (actually is worse - it dies at the window.opener.location.href):
this is what I have now:
if (window.opener.closed)
{
query = window.location.search;
uid = query.substr(5)
window.location = "logout.php?uid=" + uid + "&logout";
}
else
{
if (window.opener.location)
url_opener = window.opener.location;
else
url_opener = "outside";
document.getElementById("test").innerHTML = "url=" + url_opener + "...";
document.title = url_opener;
}
I've include the complete function as it is at the moment this time round...
in my version it seems to fail on the innerHTML line...
senshi
11-22-2004, 07:56 AM
Ok...
Have you though about this,
The window you open is opened by what method?
a plain old window.open() or var x=window.open()
var x should be a bool value that represents the window status and all the environment variables and you should get other information about the opened window.
Anyway, IM guessing on the large part, but here is
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/obj_window.asp
It should tell you what you need to know.
Horus_Kol
11-22-2004, 08:32 AM
this popup is opened by a simple window.open()
okay, it's this simple - is there are way of testing if an item exists, like in PHP there is the isset() test...
Horus_Kol
11-22-2004, 08:48 AM
found it:
if (typeof(this.opener.location) != "undefined")
this tells me that the property is defined in all cases (either navigating within the site, or outside of the site).
However, when the property is put into a string:
document.getElementById("test").innerHTML = "url=" + this.opener.location + "...";
it is okay as long as i stay within my intranet, but as soon as I navigate outside of it it goes kaput
senshi
11-22-2004, 06:34 PM
well it wont hurt if you chage the window opening routine to include a variable, you then can try various properties and methods on the variable to see whats in it.
eg
if you said...
var myX=window.open('www.htmlforums.com"','','');
document.write(myX.window.length);
you get a value of zero returned, everything else either returns
[object]
undefined
or an alert saying Access denied!
Other than that, I dont know what else to suggest.
Jon Hanlon
11-22-2004, 07:12 PM
if (self.opener && self.opener.location)
url_opener = self.opener.location;
else
url_opener = "outside";
document.getElementById("test").innerHTML = "url=" + url_opener + "...";
document.title = url_opener;
One thing about JS is that it screams if it can't find an object when you're "going down the dots".
So, if you want to check if (a.b.c.d.e) , and say c doesn't exist, you'll get an error.
You need to chain your tests:
if (a && a.b && a.b.c && a.b.c.d && a.b.c.d.e)
Now as the parser will stop at the first missing object, all will be OK.
And if you're interested in the window object, then use window. or self.
this. can have a different meaning, especially inside a function!
Horus_Kol
11-22-2004, 08:02 PM
I tried this:
if (window.opener.location)
url_opener = typeof(window.opener.location);
else
url_opener = "outside";
and in both cases (a link within my intranet, and navigating out of the intranet - to google.com, for example) there is an object defined there....
the problem comes when I am trying to get the value of window.opener.location into a string (but only when I navigate out of my intranet - all internal links give the expected behaviour).
Jon Hanlon
11-22-2004, 09:03 PM
How are you opening the pages?
The opener property is available only from a page opened using the window.open method.
Horus_Kol
11-23-2004, 03:58 AM
it is opened using the window.open property on an unload event...
the object exists all the time, but whenever I navigate outside of my intranet, i get a javascript error whenever i try to do something with the value in the location object...
Horus_Kol
11-26-2004, 04:53 AM
After much wailing and gnashing of teeth, I was introduce to try...catch
try
{
if (window.opener.location != "")
{
url_opener = window.opener.location;
}
}
catch(e)
{
url_opener = "outside";
}
document.getElementById("test").innerHTML = "url=" + url_opener + "...<br>" + e;
Works fine now :)
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.