Write a dynamic iframe

Hi,

I wonder if the following is coded correctly:

<!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

It should work, but, instead of <\/iframe> it should be </iframe>.

<!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 :cool:

Thanks for the answer, but that way your code doesn’t pass HTML validation.

I did not notice the DOCTYPE declaration. I thought that the <\TAGNAME> where only for self-closing tags.

See you :cool: