我想知道是否有HTML5的iFrames替代方案。 我的意思是,能够在一个网页中注入跨域HTML,而不使用iFrame。
当前回答
你可以使用object和embed,像这样:
<object data="http://www.web-source.net" width="600" height="400">
<embed src="http://www.web-source.net" width="600" height="400"> </embed>
Error: Embedded data could not be displayed.
</object>
这并不新鲜,但仍然有效。但我不确定它是否具有相同的功能。
其他回答
An iframe is still the best way to download cross-domain visual content. With AJAX you can certainly download the HTML from a web page and stick it in a div (as others have mentioned) however the bigger problem is security. With iframes you'll be able to load the cross domain content but won't be able to manipulate it since the content doesn't actually belong to you. On the other hand with AJAX you can certainly manipulate any content you are able to download but the other domain's server needs to be setup in such a way that will allow you to download it to begin with. A lot of times you won't have access to the other domain's configuration and even if you do, unless you do that kind of configuration all the time, it can be a headache. In which case the iframe can be the MUCH easier alternative.
正如其他人提到的,你也可以使用embed标签和object标签,但这并不一定比iframe更高级或更新。
HTML5更倾向于采用web api从跨域获取信息。通常web api只返回数据而不是HTML。
object是HTML5中一个简单的替代方案:
<对象数据= " https://github.com/AbrarJahin/Asp.NetCore_3.1-PostGRE_Role-Claim_Management/ " 宽度= " 400 " 身高= " 300 " type = " text / html " > 替换内容 < /对象>
你也可以尝试embed:
<嵌入src = " https://github.com/AbrarJahin/Asp.NetCore_3.1-PostGRE_Role-Claim_Management/ " 宽度= 200 身高= 200 onerror="alert('URL无效!!');"/>
Re-
目前,StackOverflow已经关闭了对显示外部URL内容的支持,运行代码片段不显示任何内容。但对于您的网站,它将完美地工作。
你可以使用object和embed,像这样:
<object data="http://www.web-source.net" width="600" height="400">
<embed src="http://www.web-source.net" width="600" height="400"> </embed>
Error: Embedded data could not be displayed.
</object>
这并不新鲜,但仍然有效。但我不确定它是否具有相同的功能。
这似乎也可以工作,尽管W3C指定它不是“用于外部(通常是非html)应用程序或交互式内容”。
<embed src="http://www.somesite.com" width=200 height=200 />
更多信息: http://www.w3.org/wiki/HTML/Elements/embed http://www.w3schools.com/tags/tag_embed.asp
可以使用XMLHttpRequest将页面加载到div(或页面的任何其他元素)中。一个例子函数是:
function loadPage(){
if (window.XMLHttpRequest){
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}else{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("ID OF ELEMENT YOU WANT TO LOAD PAGE IN").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","WEBPAGE YOU WANT TO LOAD",true);
xmlhttp.send();
}
如果您的服务器是有能力的,您也可以使用PHP来完成此工作,但由于您要求的是HTML5方法,因此这应该是您所需要的全部。