admin管理员组文章数量:1295863
I am creating an object element dynamically in jQuery, to render some content. It works in all browsers except IE8.
The code:
j$(document).ready(function(){
j$('.objContainer').html(j$('<object>').attr(
{'data':'',
'type':'text/html'}));
});
The HTML structure created after the execution(in IE8):
<object type="text/html"></object>
In other browsers[IE9, Firefox, Chrome]:
<object data="" type="text/html"></object>
Any solutions?
I am creating an object element dynamically in jQuery, to render some content. It works in all browsers except IE8.
The code:
j$(document).ready(function(){
j$('.objContainer').html(j$('<object>').attr(
{'data':'http://www.stackoverflow.',
'type':'text/html'}));
});
The HTML structure created after the execution(in IE8):
<object type="text/html"></object>
In other browsers[IE9, Firefox, Chrome]:
<object data="http://www.stackoverflow." type="text/html"></object>
Any solutions?
Share Improve this question edited Jan 1, 2014 at 12:55 ipradhansk asked May 3, 2013 at 22:17 ipradhanskipradhansk 3521 gold badge10 silver badges37 bronze badges 2- I suspect this is due to same-origin policy restrictions in IE8. From MSDN: In IE9 Standards mode, the object element is allowed to load content from other domains. In IE8 Standards mode, however, this is not allowed. – bfavaretto Commented May 3, 2013 at 22:25
- Just a guess, but could it have something to do with stackoverflow. using X-Frame-Options to prevent embedding, and IE reacting to that weirdly? Try embedding example.iana – Dagg Nabbit Commented May 3, 2013 at 22:48
3 Answers
Reset to default 3Works for me: using the IE8 developer tools, I can see the data attribute. Here's a screenshot.
(I know I shouldn't have to say it, but: you need to make sure that you're allowing scripts to run.)
as you see here, data (dataset) is not supported by IE.
What you can do is rename data to data-foo and then $(..).data("foo")
will work
even in IE because of a special handling by jquery itself.
This is a way to bypass dataset limitation for IE.
It should work fine, Though i remend you use $.data() method
http://api.jquery./jQuery.data/
It is much safer, and jQuery ensures that the data is removed when DOM elements are removed via jQuery methods.
Example:
<object id='myObj' data-url="http://www.stackoverflow." type="text/html"></object>
And you can read the value like:
var url = $('#myObj').data('url');// Read the value
$('#myObj').data('url', 'some-other-value');// Set a new value
本文标签: javascriptUnable to set 39data39 attribute for 39Object39 tag in jQuery IE8 onlyStack Overflow
版权声明:本文标题:javascript - Unable to set 'data' attribute for 'Object' tag in jQuery. [IE8 only] - Stack Overf 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741618685a2388679.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论