javascript - auto height for the <object> element with the embedded content - Stack Overflow

I am trying to get the auto height for the <object> element according to the embedded content in

I am trying to get the auto height for the <object/> element according to the embedded content inside. Is this possible?

An example of the issue is here: JSFiddle. Here In Chrome, it seems the auto is ignored. How can I fix this?

HTML

<body>
    <object id="my-object" data=".txt"></object>
</body>

CSS

#my-object {
    height : auto;
    width : 300px;
}

EDIT I want to make the object as big as its content, so as to avoid the scroll of object element. It should be page scroll instrad of object elements scroll.

I am trying to get the auto height for the <object/> element according to the embedded content inside. Is this possible?

An example of the issue is here: JSFiddle. Here In Chrome, it seems the auto is ignored. How can I fix this?

HTML

<body>
    <object id="my-object" data="http://www.rfc-editor/rfc/rfc1.txt"></object>
</body>

CSS

#my-object {
    height : auto;
    width : 300px;
}

EDIT I want to make the object as big as its content, so as to avoid the scroll of object element. It should be page scroll instrad of object elements scroll.

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked May 22, 2014 at 7:27 Manu K MohanManu K Mohan 8334 gold badges9 silver badges29 bronze badges 6
  • 1 btw, you don't have to declaire height for auto. default value of height IS auto. you try to make the object as big as the content ? so there is nothing to scroll ??? – Dwza Commented May 22, 2014 at 7:32
  • @Dwza That is my problem, I want to make the object as big as its content, so as to avoid the scroll. – Manu K Mohan Commented May 22, 2014 at 7:48
  • Well, this isn't a good way but it works. If you inspect the puted style of the object, you'll see that it has height:16155px and so you can add some fixed height to the object like 17000px to remove the scrollbar - JSFiddle – Vucko Commented May 22, 2014 at 7:59
  • @Vucko Can we make it dynamic? I mean if I want to dynamically change the data-url. How will I get the height? – Manu K Mohan Commented May 22, 2014 at 8:39
  • Vucko just gave the answer for you if you can use JS you need to get puted height please check jQuery outerHeight if you cannot use jQuery look at Window.getComputedStyle() also look browser patibility. The only problem is when you should get it check if object has onload/success event if it has you are pretty much done. – Onur Topal Commented May 22, 2014 at 9:11
 |  Show 1 more ment

3 Answers 3

Reset to default 0

it must be run under a server

with "contentDocument()"

<object id="my-object" type="text/plain" data="newfile.txt">
</object>
<script>
    var object = document.getElementById("my-object");
    object.onload = function () {
        var objectPre = object.contentDocument.body.childNodes[0];
        object.style.height = (objectPre.offsetHeight+20) + "px";
    };
</script>

with ajax do a search on loading the txt file using ajax

working fiddle (100% height, min-height and overflow hidden to body and html elements )

http://jsfiddle/DmF6B/2/

html, body{
   overflow:hidden;
   height: 100%;
   min-height: 100%;
}
    #my-object {
        height : 100%;
        width : 100%;
        overflow : hidden;
    }

html

<body scroll="no">
    <object id="my-object" data="http://www.rfc-editor/rfc/rfc1.txt">
    </object>
</body>

if it is in the same domain use the javascript function "contentDocument()"

try this instead : ajax

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742352127a4427728.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信