Passing Javascript variable to HTML?

J

John

Hi all,
Hope someone can help.
I need to fill an iFrame with an html page. The page to load is determined by a regular navigation
button.
I can use Javascript to set a variable depending on which nav button is clicked.
What I can't figure out is how to pass that variable's value to the iFrame's 'src=' attribute.

Any ideas anyone?
TIA
 
T

Trevor L.

John said:
Hi all,
Hope someone can help.
I need to fill an iFrame with an html page. The page to load is
determined by a regular navigation button.
I can use Javascript to set a variable depending on which nav button
is clicked.
What I can't figure out is how to pass that variable's value to the
iFrame's 'src=' attribute.

Any ideas anyone?
TIA

I do it this way

<button onclick="loadIframe('News','news.html')">Open/Close News of this Site</button>
<iframe class="c1" id="News" src=""></iframe>

where
function loadIframe(id,sPath)
{
var x = document.getElementById(id)
if (x.style.display != 'block')
{ x.src = sPath
x.style.display = 'block'}
else
x.style.display = 'none'
}
and where
..c1 {
display: none;
height: 200px;
width: 400px;
overflow: auto;
}

This actually loads the page on one click and on another click hides it. Just amend as you need to
Possibly as (not tested)
<button onclick="loadIframe('News','news.html')">Open News of this Site</button>
<iframe class="c1" id="News" src=""></iframe>

function loadIframe(id,sPath)
{
var x = document.getElementById(id)
if (x.style.display != 'block')
{ x.src = sPath
x.style.display = 'block'}
}
This should load the page, but not hide it again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top