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
Add a ment  | 

3 Answers 3

Reset to default 3

Works 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