Click to See Complete Forum and Search --> : Referring to url in iframe from external array


bhollin
09-24-2003, 05:14 PM
I have an iframe that works fine, as long as it contains src="myurl", for example:

<iFrame width="510" height="326" src="myurl" name="textbox" border="0" bordercolor="#ffffff" hspace="0" vspace="0" marginwidth="4" marginheight="1" scrolling="auto" frameborder="0"></iFrame>

What I'm trying to do is to externalize the url in an array for easier maintenance. My array looks like:

var framedoc=new Array(2)
framedoc[0]="myurl1"
framedoc[1]="myurl2"

I can't seem to figure out the right syntax to replace the src="myurl" in the iframe with a reference to the url in the array. I presume it's something like: src=document.array.framedoc[0] or src=document.framedoc[0].src, but don't seem to have it right. What's the correct syntax? Thanks.

skriptor
09-25-2003, 07:55 AM
Hi, try something like this:

<html><head>
<script type="text/javascript" language="JavaScript">
var framedoc=new Array(2)
framedoc[0]="kiki.htm"
framedoc[1]="koko.htm"
</script>
</head><body>
<a href="#" onclick="document.all.myF.src=framedoc[0];return false">url1</a><br />
<a href="#" onclick="document.all.myF.src=framedoc[1];return false">url2</a><br />
<iFrame id="myF"width="150" height="150" src="kiki1.htm" name="textbox" border="0" bordercolor="#ffffff" hspace="0" vspace="0" marginwidth="4" marginheight="1" scrolling="auto" frameborder="0"></iFrame>
</body></html>

good luck