Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read the URL of the Frame from another window

Status
Not open for further replies.

TechnicalAnalysis

Programmer
Jul 2, 2001
169
0
0
US
I want to read the URL of the frame in another browser opened from my page. The read URL will then display in the text field of the opener browser's form.

I thought something like this will work but no luck.

function getTheURL() {
document.FormName.fieldname.value=newWin.document.frames[1].location.href;
}

function openWin() {
var newWin=window.open(url,"InWin");
setTimeout("getTheURL()",10000); //wait about 10 seconds
}

Where the form with name FormName is in the opener window.

I got the error of newWin.document has no properties. Not sure why? Any suggestion is appreciated.

Regards

 
Remove "document" from here: newWin.document.frames[1].location.href,

The [tt]frames[/tt] array is a property of both the [tt]Frame[/tt] and [tt]window[/tt] objects, but not of the [tt]document[/tt] object.

It should be
newWin.frames[1].location.href

 
Star way

Thansk for your reply.I tried to just reading the url of the opening browser. It means it should read the same url of the opening browser. I got the same error.
I'm not sure if it's the Frames issue.
This doens't work either

function getTheURL() {
document.FormName.fieldname.value=newWin.document.location.href;
}

Any idea?
 
try removing the .document from the right side of =.

newWin.location; The only dumb questions are the ones that are never asked
 
twcman

I also agree with what you said and tried to see if it works. The outcome is negative. This is driving me nuts as it should be an easy task.
The browser keeps telling me that newWin is undefined.
And I think I did define it in line
var newWin=window.open(url,"InWin");
Do I need to refer to the name "InWin"?
 
try this

function getTheURL() {
document.forms[0].fieldname.value=newWin.document.frames[1].location.href;
}
 
you could try combining the functions, if thats the only line of code in that function you might as well put it in the other one. :
Code:
function openWin()  {
var newWin=window.open(url,"InWin");
setTimeout("document.FormName.fieldname.value=newWin.frames[1].document.location.href",10000); //wait about 10 seconds
}

hope it helps! "Those who dare to fail miserably can achieve greatly." - Robert F. Kennedy
So true..
 
you need to make newWin a global var - declare it outside any function.
[tt]
var newWin;

function getTheURL() {
document.FormName.fieldname.value=newWin.parent.frames[1].location.href;
}

function openWin() {
newWin=window.open(url,"InWin");
setTimeout("getTheURL()",10000); //wait about 10 seconds
}
[/tt]
=========================================================
if (!succeed) try();
-jeff
 
Thanks for everyone suggestion though my initial post dated back in July 02.
Jeff, I tried your suggestion. I'm getting the following error message.

Permission Denied in line 5 below.

<html>
<script language=Javascript>
var newWin;
function getTheURL() {
document.FormName.fieldname.value=newWin.parent.frames[1].location.href;
}
function openWin(aurl) {
newWin=window.open(aurl,&quot;InWin&quot;);
setTimeout(&quot;getTheURL()&quot;,10000); //wait about 10 seconds
}
</script>
<body>
<form name=FormName>
<input type=text name=fieldname value=''>
<input type=button value='Get the URL' onClick=openWin('</form>
</body>
</html>

Any idea?
 
you usually get &quot;permission denied&quot; when trying to read window properties of a document that is not in your domain - javascript does not allow this for security reasons. is this the case with your frame?
=========================================================
if (!succeed) try();
-jeff
 
Yes, it's the case.I was trying to automate a process that I need to know the url in a frame of that web application six months ago.
Thanks for your tips. I guess it's just not the way to go.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top