admin管理员组文章数量:1334133
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 hasheight:16155px
and so you can add some fixed height to theobject
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
3 Answers
Reset to default 0it 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
本文标签: javascriptauto height for the ltobjectgt element with the embedded contentStack Overflow
版权声明:本文标题:javascript - auto height for the <object> element with the embedded content - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742352127a2458704.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论