Forum Moderators: open
I was reading an older post (http://www.webmasterworld.com/forum91/2042.htm) and I can't get my modification to work.
I'm trying to dynamically show the iframe url in the text field below it, as the person browsers around in the URL. With no luck but :\
------------------------------------------------------------
<html><body>
<iframe id="myframe" name="myframe" src="http://www.google.com"
style="height: 90%; width:100%; margin: 0 0 0 0; border: 0px;">
</iframe><br>
<script type="text/javascript" language="JavaScript">
document.write('<input type="text" style="width:100%; " ');
document.write(' value="' + document.getElementById('myframe').document.URL + '">');
</script>
</body></html>
------------------------------------------------------------
Many thanks in advance for your suggestion and assistance,
Manic_Monday
from this
document.getElementById('myframe').document.URL
to this
document.getElementById('myframe').src
this ensures that you are getting the ifames source value and not the documents url
<html><body>
<iframe id="myframe" name="myframe" src="http://www.google.com"
style="height: 90%; width:100%; margin: 0 0 0 0; border: 0px;">
</iframe><br>
<script type="text/javascript" language="JavaScript">
document.write('<input type="text" style="width:100%; " ');
document.write(' value="' + document.getElementById('myframe').src+ '">');
</script>
</body></html>
But unfortuantely src only gets the source value and not the actual iframes URL.
And for example, since people will navigate away from google.com in the iframe what I need is the URL they are visiting.
I need the text field "myfield" to display the iframes URL just like the Address Bar does for the window.
I've placed a button next to the text field so that onclick get URL of iframe (currently it writes to an alert and I'm having all sorts of trouble getting it to write to the textfield "myfield")
------------------------------------------------------------
<html><body>
<iframe id="myframe" name="myframe" src="http://www.google.com"
style="height: 90%; width:100%; margin: 0 0 0 0; border: 0px;">
</iframe><br>
<input type="text" style="width:92%;" name="myfield" id="myfield">
<button sty style="" onclick="alert(document.getElementById('myframe').url)">get url</button>
</body></html>
------------------------------------------------------------
Let me know what you think,
Cheers Manic Monday
As RamboTribble mentioned, you will not be able to read the href of the document contained in the iframe if the document is located on a different domain than yours even though you can change the href. Kinda reminds me of a friend of mine that invented Write-Only-Memory (WOM). It never really took off, though.
ajkimoto