开发者

Remove <object> from dom on ipad

开发者 https://www.devze.com 2023-04-11 15:03 出处:网络
I\'m working on a projet where a page is loaded through an 开发者_开发知识库object that is dynamically generated with jquery. This is an iPad project.

I'm working on a projet where a page is loaded through an 开发者_开发知识库object that is dynamically generated with jquery. This is an iPad project.

When the user is done with page there is a call to remove the object from the dom. Using something like $('#objectName').remove(); crashes safari on ipad. This does not happen on the desktop browsers. I tried to use an iframe but the result is the same.

How can I remove the object without the iPad crashing?

I tried wrapping the object in a div and removing or hiding that div but with weird results. It crashes still when I remove the div and hiding the div still leaves the object visible.

Thanks for all of the help!


I know this is a pretty old thread, but for the people who run into this I have a fix for the problem:

For me, the issue only appeared when I was trying to remove an object from the DOM with an iframe in it.

To fix it, I first tried setting the iframe's src to nothing before(!) removing the element from the DOM like this:

$('div.lightbox iframe').attr('src',''); 

This didn't fix the issue completely, it worked but when it was the case that the iframe content was still loading when I removed the element from the DOM (I was loading the content in a lightbox element, and closing the lightbox (thus removing the element from the DOM) it still crashed the browser.

I fixed the issue completely by setting the HTML of the element to be removed to nothing, again before(!) removing the element from the DOM like this:

$('div.lightbox').html(''); 

So here, the final solution:

$("div.lightbox").fadeOut(500, function(){

    $('div.lightbox iframe').attr('src',''); 
    $('div.lightbox').html(''); 

}).remove();        
0

精彩评论

暂无评论...
验证码 换一张
取 消