Forum Moderators: open

Message Too Old, No Replies

Need to refresh Iframe using Javascript

Need to refresh Iframe using Javascript

         

rahulbhatt

8:56 pm on Sep 1, 2010 (gmt 0)

10+ Year Member



Hi

My web page has a Iframe on it I want to change src attribute with a Java script function but it seems that it dosnt work
<script language="javascript">

function getLoginPageurl ()
{
// logic
return url;
}
</script>

<iframe id="myframe" name="myframe" src="javascript:getLoginPageurl()">iframe not supported</iframe>

I am getting a Java script error that says getLoginPageurl is not defined. Any Idea


Rahul

daveVk

1:09 am on Sep 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



src="javascript:getLoginPageurl()"

I think this is interpreted as, create empty Iframe, then execute getLoginPageurl() within the context of the iframe. getLoginPageurl is not defined within that context( the iframe window ).

Instead use

<script>
document.getElementById("myframe").src = getLoginPageurl();
</script>

Depending on the logic of getLoginPageurl you may need to wait until page load before executing this.