Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在IE上的对象中显示远程html?_Javascript_Internet Explorer_Html - Fatal编程技术网

Javascript 如何在IE上的对象中显示远程html?

Javascript 如何在IE上的对象中显示远程html?,javascript,internet-explorer,html,Javascript,Internet Explorer,Html,我尝试在IE上显示失败的对象中嵌入html。下面是js代码 document.getElementById('one').innerHTML = '<'+'object id="foo" name="foo" type="text/html" data="'+which.href+'"><\/object>'; document.getElementById('one')。innerHTML=''; 这是html <div id="one"><ob

我尝试在IE上显示失败的对象中嵌入html。下面是js代码

 document.getElementById('one').innerHTML = '<'+'object id="foo" name="foo" type="text/html" data="'+which.href+'"><\/object>';
document.getElementById('one')。innerHTML='';
这是html

<div id="one"><object id="foo" name="foo" type="text/html" data="$jsurl/animate/right/ap2.html"></object></div>

代码可以在其他浏览器上正确显示,但不能在IE上显示,IFRAME不是一个选项,因为我需要它是透明的,以便覆盖在div的顶部


需要知道如何在IE或任何其他选项上显示它吗?

您可以使用XmlHttpRequest对象获取远程HTML文件的内容,然后将HTML代码作为div的innerHTML插入

代码可以是这样的:

var request = null;

if (window.XMLHttpRequest) {
     // If IE7, Mozilla, Safari, and so on: Use native object.
      request = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
     // ...otherwise, use the ActiveX control for IE5.x and IE6.
     request = new ActiveXObject('MSXML2.XMLHTTP.3.0');
}

request.open('GET', '$jsurl/animate/right/ap2.html', false); 
request.send();

if (request.status == 200) {
    document.getElementById('one').innerHTML = request.responseText;
}

不太确定这应该如何工作。我把你的代码放在和之间,放在身体里。URL在request.open中显示正确,但在div中没有显示。我遗漏了什么吗?嗯,HTML文件的URL($jsurl/animate/right/ap2.HTML)看起来很奇怪,应该是这样的http:///animate/right/ap2.html 或者只是/animate/right/ap2.html。。。那么$jsurl文本呢?它是一个JavaScript变量还是什么?$jsurl是一个php变量,当我检查页面源代码时,它正确地显示为http://localhost/animate/right/ap2.html(我正在本地机器上测试)。顺便说一句,我把URL改为http://www.google.com。它也不加载。只是看到了错误的原因。未捕获的错误:NETWORK\u ERR:XMLHttpRequest异常101。尝试加载google.com是的,您无法使用XmlHttpRequest对象从另一个域加载内容