www.webdeveloper.com
Results 1 to 3 of 3

Thread: How can I load an iframe with Javascript?

  1. #1
    Join Date
    Mar 2010
    Posts
    701

    How can I load an iframe with Javascript?

    I want to load an iframe with Javascript after my HTML finishes loading, but I also want people without Javascript to be able to view it. How can I do that?

    Maybe I can create the iframe with a src, and remove the src with Javascript before the iframe loads. Then load the iframe after the page loads. How do I do that?

  2. #2
    Join Date
    Mar 2009
    Posts
    497
    What I might suggest is enclosing the HTML iframe within a pair of <noscript> tags. If javascript is not enabled on the user's browser, this should be visible.

    And as for your javascript, you should have something like:

    Code:
    window.onload = function(){
        var x =document.createElement('iframe');
        x.scr = 'whatever.png';
        document.body.appendChild(x);
    }
    And no, I don't know if this will work or not.

    // SORRY--"whatever.png" should be an url in the suggested code above.
    Stupid is as stupid does.
    Last edited by Tcobb; 01-31-2011 at 02:54 PM. Reason: Even if I am not an idiot, I have a great talent for acting like one

  3. #3
    Join Date
    Mar 2010
    Posts
    701
    I never thought of <noscript>. Thanks, I will try that and see if it works!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles