jquery - javascript populate iframe, modify source in one -


Contain content of 2 iframes with the same HTML preview. However for one of the iframes, I need to modify the data / html by removing images. $ Ajax ({url: '', datatype: 'text', success: function (data) {if (data) {var iframe = document.getElementById ('preview'); Iframe.parentNode.style.display = "block"; Iframe = (iframe.contentWindow)? Iframe.contentWindow: (iframe.contentDocument.document)? Iframe.contentDocument.document: iframe.contentDocument; iframe.document.open (); Iframe.document.write (data); iframe.document .close (); var iframe = document.getElementById ('preview-noimgs'); iframe.parentNode.style.display = "block"; iframe = (iframe.contentWindow)? iframe.contentWindow: (iframe.contentDocument.document) ? Iframe.contentDocument.document: iframe.contentDocument; iframe.document.open (); var $ data = $ (data); $ data.find ("img"). RemoveAttr ("src"); iframe.document.write ($ Data.html ()); iframe.document.close ();}}});

It gives me: NULL or depends on the object object if I .html ()

What is the correct way to modify the source?

I did not read through jquery docs parse HTML () but unfortunately it would not be able to use it because we are limited to version 1.7.1. The way?

Preview:

Keep in mind that .html () Internal HTML , not external HTML

I think you should try it instead:

  var $ data = $ ("& Lt; div>;" + data + "");   

By adding a div wrapper, you can ensure that $ data.html () returns the correct original node.

If you are adding a full HTML page to the Iframe, then you can try it:

  iframe = document.getElementById ('preview-noimgs'); iframe.parentNode.style.display = "block"; Var iframeWindow = (iframe.contentWindow)? Iframe.contentWindow: (iframe.contentDocument.document)? Iframe.contentDocument.document: iframe.contentDocument; iframeWindow.document.open (); iframeWindow.document.write (data); IframeWindow.document.close (); .. $ (Iframe) .contents () looks ("html") sounds ("img") removeAttr ("src"). Remove // ​​`src`    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -