Replace Entire Content of Iframe

前端 未结 4 1158
鱼传尺愫
鱼传尺愫 2020-12-29 08:11

Is there a way to replace the ENTIRE contents of an iframe using Javascript (or Jquery)?

For example if my iframe had the following content...

blah o         


        
4条回答
  •  青春惊慌失措
    2020-12-29 08:37

    I am having the same issue, and if i use the code like this:

    $(youriframe).contents().find('html').html('your content here'); 
    

    It works fine in Chrome or FireFox, but in IE8, nothing will be showed or the scroll bar in iframe won't appear.

    If i use Rachel's method, the iframe content will be like this in all browsers:

    
    

    is there any other solution?

    Tried this one:

    var doc = document.getElementById(iframeId).contentWindow.document;
    doc.open();
    doc.write(iframeContent);
    doc.close();
    

    this works on my case, both ie8 and FF/chrome.

提交回复
热议问题