2

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.

7
  • 2
    JSFiddle jsfiddle.net/jwpc9 Commented Feb 27, 2012 at 12:09
  • 1
    i created a fiddle, that seems to work as posted: jsfiddle.net/BLfGd Commented Feb 27, 2012 at 12:09
  • Are you setting the height/width of the div or the object? Seems to work for me: jsfiddle.net/bKws9 Commented Feb 27, 2012 at 12:10
  • I take it you'd like to see the markup from welcome.html inserted into the stream of your main page. Using an object tag won't do that. You could try to create an iframe directly 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. Commented Feb 27, 2012 at 12:11
  • I tried setting the height/width of the DIV, but no go. But setting of the object does! Go figure. Commented Feb 27, 2012 at 12:21

2 Answers 2

3

Can you use jquery? Then it becomes trivial...

$('#main').load('welcome.html');
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.