PDA

View Full Version : Iframe with address bar



Chrismr3000
08-18-2009, 05:49 AM
i wanted to know if there was any code that shows an iframe with an address bar, kinda like a browser?

here's the iframe code i already have

<div align="center">
<iframe name="iframe" src="http://allaboutnetwork.freeforums.org/index.php" width="1125" height="1750" scrolling=yes frameborder=0></iframe>
</div>

thanks :D

Nile
08-18-2009, 05:51 AM
Do you want a text input so you type in the site press enter and it goes to it? Or what?

Chrismr3000
08-18-2009, 09:04 PM
actually no, i want it so people can see the address and only copy it, but have it integrated with the iframe

Nile
08-19-2009, 02:30 PM
Ok, Here:


<script type="text/javascript">
var _ = function(id){ return document.getElementById(id); };
window.onload = function(){
var text = document.createElement('p');
var url = document.createTextNode(_('iframe').getAttribute('src'));
text.appendChild(url);
_('url').appendChild(text);
};
</script>
<div id="url">

</div>
<div align="center">
<iframe name="iframe" id="iframe" src="http://allaboutnetwork.freeforums.org/index.php" width="1125" height="1750" scrolling=yes frameborder=0></iframe>
</div>

Chrismr3000
08-19-2009, 02:55 PM
theres a preoblem, i pasted the code but when i click alink within the frame the text just shows "http:/allaboutnetwork.freeforums.org". I want the text to be dynamic.

thenajsays
08-19-2009, 08:23 PM
the iframe changes depending on the link?

Chrismr3000
08-19-2009, 09:42 PM
the iframe changes depending on the link?

no, the iframe first opens up as the link to my forum, nile made a great code of kinda what i wanted but the text just says my forums home address, what i want is to have THAT text change to the address of what i am browsing in the iframe and every time the url changes i want that text to change with the changing url of the iframe.

that understandable?

thenajsays
08-20-2009, 10:48 AM
cool... thats what i thought you meant... lemme think about it and ill see what i can come up with

Chrismr3000
08-20-2009, 10:09 PM
k, thanks. i sadly haven't seen a code for this, hope someone can make it

thenajsays
08-21-2009, 02:09 AM
its impossible to do unless the iframe href is within the same domain as the parent window... i hope this helps

thenajsays
08-21-2009, 02:10 AM
wait a sec, i added a reply with some code earlier today and its gone? what happened? did you happen to see it? if not let me know and ill repost tomorrow

Chrismr3000
08-21-2009, 03:06 AM
oh, thanks but you give me an example since im not really acquainted with HTML

thenajsays
08-21-2009, 12:07 PM
ok, heres what i got... i must not have posted it or something... like i said before, it will only work if the link thats clicked in the iframe is on the same domain as the parent window. for example: the main window is www.yoursite.com. all the links in the iframe must me yoursite.com/nextpage... make sense? if you tried to like to, lets say google, it wouldnt work.

<html>
<body onLoad="document.getElementById('addressBar').innerHTML = document.getElementById('myIframe').src" style="font-family:Verdana, Geneva, sans-serif; text-align:center">
<div style="width:494px; height:14px; border:solid 1px #000000; font-size:12px; margin:0 auto; padding:3px" id="addressBar"></div>
<iframe onLoad="document.getElementById('addressBar').innerHTML = document.getElementById('myIframe').contentWindow.location.href" id="myIframe" style="width:500px; height:500px; border:solid 1px #000000; font-size:12px; margin:0 auto; padding:3px" src="page1.html"></iframe>
</body>
</html>

Chrismr3000
08-21-2009, 05:48 PM
but wouldn't that defeat the whole purpose of the iframe

thenajsays
08-21-2009, 08:45 PM
no... the iframe will still work, javascript just cant get the href (the URL of the iframe content) if its not on your domain.