SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Dec 2010
    Posts
    227
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Write a dynamic iframe

    Hi,

    I wonder if the following is coded correctly:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html> 
    <head> 
    <title>Sample Page</title>
    </head> 
    <body> 
    <div id="container"></div>
    <script type="text/javascript">
    var url = "http://www.example.com/";
    var content = "<iframe width='800' height='600' frameborder='0' src='" + url + "'><\/iframe>";
    document.getElementById("container").innerHTML = content;
    </script>
    </body>
    </html>
    Many thanks in advance!
    Mike

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Location
    Bs. As. - Argentina
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should work, but, instead of <\/iframe> it should be </iframe>.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html> 
    <head> 
    <title>Sample Page</title>
    </head> 
    <body> 
    <div id="container"></div>
    <script type="text/javascript">
    var url = "http://www.example.com/";
    var content = "<iframe width='800' height='600' frameborder='0' src='" + url + "'></iframe>";
    document.getElementById("container").innerHTML = content;
    </script>
    </body>
    </html>
    By the way, innerHTML is a De facto standard it will be better to use more standard methods like "createElement", "appendChild" and so on....

    See you

  3. #3
    SitePoint Addict
    Join Date
    Dec 2010
    Posts
    227
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pablogo View Post
    It should work, but, instead of <\/iframe> it should be </iframe>.
    Thanks for the answer, but that way your code doesn't pass HTML validation.

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Location
    Bs. As. - Argentina
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did not notice the DOCTYPE declaration. I thought that the <\TAGNAME> where only for self-closing tags.

    See you


Bookmarks

Posting Permissions

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