Page 1 of 1

current src of iframe with getElementById?

Posted: Sun Nov 19, 2006 9:49 pm
by potato
hello everybody,

to detect the url of a iframe with javascript, i've got following code:

Code: Select all

<a href="#" onClick="alert(document.getElementById('browser').src)">Show the current url</a>
the iframe has the src set to http://video.google.com and the id = browser.

The result is http://video.google.com, even if the page in the iframe isnt that anymore.

I need to have the current src, not the start src.

any help would be great.

greetings,
tom

Posted: Mon Nov 20, 2006 2:24 pm
by feyd
.document.location.href

Posted: Mon Nov 20, 2006 3:02 pm
by potato
nope, that gives the url of the current page that hosts the iframe.

Have a look at this page:

http://www.mytuningcar.be/videos/browser.php

You see that the link isn't in the iframe, but on the page that holds that iframe.

When you click on it, it shows you: http://video.google.com even if the iframe isn't on that page anymore.

Posted: Mon Nov 20, 2006 3:42 pm
by feyd
The leading dot should be of note.... it would go with your call to getElementById.

Posted: Wed Nov 22, 2006 7:43 am
by n00b Saibot
I can confirm the findings of Bevibed.be and I am still unable to find a correct solution ot hte abov problem. If any one knows a solution to this I will be thankful to him. It's very rare for me to get stuck on a JS problem :(

Posted: Wed Nov 22, 2006 8:05 am
by potato
pk, ive heard that its impossible to detect when the src in the iframe is extern.
Otherwise it would give cross site scripting 'xss'.

Security :(

I think we can close this topic, but if in the future somebody knows another solution, shoot! ;)

greetings and thanx for your time