Click to See Complete Forum and Search --> : iframe src as variable
zbgump
11-25-2003, 03:07 AM
I hate asking questions when I know the answer is obvious, but here goes...
A friend of mine helped me out with a script to set a variable to the appropriate url for my iframe.
How do I set the src of the iframe to equal the variable, in the html body?
Thanks.
Gollum
11-25-2003, 03:21 AM
If you have
<iframe id="miFrame">
then you can
document.getElementById('miFrame').src = url;
zbgump
11-25-2003, 04:43 AM
Thanks for the re Gollum. I'm pretty new to javasript; I've been playing around with your recommendation and I'm just confusing myself further.
var iframe_url = ''
if (product.length > 0 ){
iframe_url = '/product_pages/set_pages/'+ product+ '.html ';
else
iframe_url = '/product_pages/set_pages/thing.html';
}
Thats part of the code I have to set "image_url".
Now for <iframe src = "X" > What goes where "X" is? Or am I going about this the wrong way still?
TIA
zbgump
11-25-2003, 05:29 AM
Looking over the post, I'm not sure I've been clear.
The varible gets set in the head of the page; depending on wether or not a variable string is attached to the url.
I need that variable to set which url is loaded in to my iframe.
Gollum
11-25-2003, 06:12 AM
in your document body...
<script type="text/javascript">
document.write('<iframe src="' + iframe_url + '"></iframe>');
</script>
zbgump
11-26-2003, 01:32 AM
Thanks alot Gollum!!:D
Gollum
11-26-2003, 03:01 AM
welcome:cool: