getElementById.contentDocument error in IE

后端 未结 6 469
不思量自难忘°
不思量自难忘° 2020-11-30 10:57

   

        
6条回答
  •  不知归路
    2020-11-30 11:59

    Use feature detection, as contentDocument is supported in IE 8:

    var iframe = document.getElementById("iView");
    var iframeDocument = null;
    if (iframe.contentDocument) {
        iframeDocument = iframe.contentDocument;
    } else if (iframe.contentWindow) {
        // for IE 5.5, 6 and 7:
        iframeDocument = iframe.contentWindow.document;
    }
    if (!!iframeDocument) {
        // do things with the iframe's document object
    } else {
        // this browser doesn't seem to support the iframe document object
    }
    

提交回复
热议问题