I'm trying to load some HTML into a DIV using JavaScript, but I can't alter the size of the DIV frame, no matter what I try. All I get is a small little frame in the middle of the browser window. I've tried CSS. I've tried 'width:' and 'height:'. Here's my code:
<div id="main">
</div>
<script type="text/javascript">
document.getElementById('main').innerHTML =
'<object type="type/html" data="welcome.html"><\/object>';
</script>
Don't concern yourself about why I want to do this -- it's part of a greater coding experiment.
Felix Kling
820k181 gold badges1.1k silver badges1.2k bronze badges
asked Feb 27, 2012 at 12:04
Richard Eng
2,0246 gold badges25 silver badges32 bronze badges
2 Answers 2
Can you use jquery? Then it becomes trivial...
$('#main').load('welcome.html');
answered Feb 27, 2012 at 12:18
pedromarce
5,6692 gold badges30 silver badges27 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
It seems to set the width
document.getElementById('main').innerHTML ='<object type="type/html" data="newhtml.html"><\/object>';
document.getElementById('main').style.width = "600px";
document.getElementById('main').style.border = "solid red 1px";
shows that the width is set to 600px
answered Feb 27, 2012 at 12:19
Manatok
5,7263 gold badges26 silver badges32 bronze badges
Comments
default
divor theobject? Seems to work for me: jsfiddle.net/bKws9welcome.htmlinserted into the stream of your main page. Using anobjecttag won't do that. You could try to create aniframedirectly and then move the parent node of the contained DOM to the main document... might work, depending on same domain policy, I'd have to try to see.