Click to See Complete Forum and Search --> : Location?????
cezza30
02-28-2003, 10:02 AM
I have a window, that upon opening, opens a new window. I want to get the location of the second window and put it in a text box on a form in the first one.
I tried:
document.URLBox.URL.value = newwin.location;
but this doesn't seem to work.
Any ideas please?!
Thank you in advance . . .
Asumbing that newwin is the name of the window that you opened, try this:
document.URLBox.URL.value = newwin.document.location;
khalidali63
02-28-2003, 10:07 AM
use newwin.left and newwin.top
should give you the correct co-ord for the window
Cheers
Khalid
Phil Karras
02-28-2003, 11:03 AM
I believe you are all wrong. I've tried this for a work project and the only thing I was able to get was the fact that the child's location had changed.
Second, If you have written both pages then
1. you know the initial location of the child page
2. the child page can pass it's location back to the parent.
Sort of unnecessary.
Anyway, if the child window now changes its location you run up against security issues and the newer browsers no longer allow you to get the URL it is now located at. As I said, best you can do (which in my case was all I needed) is determine when it has changed its location. I believe I used
onerror = handleErrors
function handleErrors(errorMessage, url, line) {
.
.
.
}
// and in another function I had:
var NewTitle = TmpPg.document.title;
to test the child window's title. This caused the error which was then trapped by the error functions and I could tell when it happened but not what page was loaded.
Also I could only tell when the first change took place since I had something to compare with, ie I could read the title from the page I had opened with the child window but I could not read the title from any other page opened by the client in that window.
It would seem like you are able to get your new window's location, as long as you are still on your domain (I'm assumbing...I did my testing on my local disk) Please view the attached file for a demonstration...
Phil Karras
02-28-2003, 12:56 PM
That would make sense, there's no security issue if you're on your own domain. In which case I'd assume the methods previously posted should work.
win = window.open("MyURL", "tmp");
and something like:
win.document.location
should work.
Yes, what I originally posted (document.URLBox.URL.value = newwin.document.location;) works just fine...
cezza30
02-28-2003, 04:59 PM
Sorry if I'm being dumb here . . . .
This is my code, and it doesn't work :(
<html>
<head>
<SCRIPT language="JavaScript">
<!-- Begin
function Home() {
window.close();
newwin.close();
}
function URL() {
top.mainFrame.location = "BookmarkDetails.html";
document.URLBox.URL.value = newwin.document.location;
}
function Open() {
newwin = window.open("NewBrowser.html","newwin",'status=0,toolbar,location=yes,resizable=1,scrollbars');
}
//-->
</SCRIPT>
</head>
<body bgColor="black" text="white" link="white" vlink="white" alink="white" onLoad="Open()">
<p align="center">
<img src="bookmark.gif">
</p>
<ul>
<li><a href="javascript:URL()">Add a Bookmark</a>
<li><a href="" target="mainFrame">Delete Bookmark</a>
<li><a href="" target="mainFrame">View a Bookmark</a>
<li><a href="" target="mainFrame">Check Bookmark</a>
<li><a href="javascript:Home()">Home</a>
</ul>
<FORM name="URLBox">
<Input type="text" name="URL">
</FORM>
</body>
</html>
As far as I can see it is how you suggested, it kind of works when the page viewed is an html file in the same folder, but as soon as you view an external web page in the second window it doesn't work.
I feel like banging my head against a wall!!!!
Thank you for being so helpful!
Originally posted by cezza30
but as soon as you view an external web page in the second window it doesn't work.You won't be able to get external (off-domain) website locations...It's a security thing...