Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    change source of iframe after page has loaded

    Im very new to java scripting so any help would be truly appreciated. I have a single web page that loads several iframes. One of the iframe pages has to be logged in first. I have that taken care of but once the page is loaded I need to change the source to a link with in the page. My guess is I need something to execute the code like a onload or something. This is what Ive been trying to get to work but like I said a newb!

    The iframe in question is named "cad"
    the initial source once loaded is 'https://urlname.com/mainmenu.asp'
    the source I need to change to is 'https://urlname.com/UnitStatusF.asp?agency_id=28'

    [CODE]
    function ChangesSrc()
    {
    var iframeid = document.getElementById(cad);
    var unitstatus = 'https://urlname.com/UnitStatusF.asp?agency_id=28'
    if (iframeid.src = 'https://urlname.com/mainmenu.asp')
    iframeid.src = unitstaus;
    return false;
    }
    [[CODE]

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,037
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    Like this:-

    Code:
    <html>
    <head>
    <script type = "text/javascript">
    function changesrc() {
    if (document.getElementById("myframe").src = "http://www.yahoo.com") {
    document.getElementById("myframe").src = "http://www.google.com";
    }
    }
    </script>
    </head>
    
    <body onload = "changesrc()">
    
    <iframe height = "500" width = "800" id="myframe" src = "http://www.yahoo.com">
    
    </div>
    </body>
    </html>
    Your closing CODE tag is wrongly shown as [[CODE]

    "I know that you believe that you understand what you think I said, but, I am not sure you realise that what you heard is not what I meant". (Robert
    McCloskey)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •