current src of iframe with getElementById?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

current src of iframe with getElementById?

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

.document.location.href
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The leading dot should be of note.... it would go with your call to getElementById.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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 :(
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

Post 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
Post Reply