Forum Moderators: open

Message Too Old, No Replies

How can I get the URL of an IFrame

Redirected URL

         

JulianD

8:58 am on Feb 24, 2006 (gmt 0)



I am trying to dynamically get the URL of the page displayed in an iFrame.

This script works:

document.write('<input type="text" style="width:100%; " ');

document.write(' value="' + document.getElementById('myframe').src+ '">');

But the source URL is being redirected (on an external server) to another URL and I want to know what this other URL is. The above script just returns the source URL.

RonPK

12:36 pm on Feb 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try to read something like
document.frames['nameOfIframe'].location.href

But you'll probably run into cross-domain restrictions: JavaScript cannot read or write properties from pages on other domains.

mrhoo

11:09 pm on Feb 24, 2006 (gmt 0)

10+ Year Member



function getremoteSrc(who){
//who is a reference to the iframe

if(who.contentWindow) d= who.contentWindow.document;
else if(frames[0]) d= frames[0].document;
return d.URL;
}