简体   繁体   English

外部html页面未在div中加载

[英]External html page not loading inside div

I am trying to load an externalpage inside div.On clicking one div I expect the another web page to be loaded inside another div.But the web page is not loading on the second div.Here is the fiddle. 我正在尝试在div内加载一个外部div.On单击一个div时我希望另一个网页可以在另一个div内加载,但是该网页不在第二个div上加载,这是小提琴。

https://jsfiddle.net/user1989/xpp5t6nv/9/ https://jsfiddle.net/user1989/xpp5t6nv/9/

<div id="fileTreeDemo_1" class="demo" onclick="alert1()">abc</div> <div id="upload_target" name="upload_target" ></div>

<style>
html,body{
    height:100%;
    width:100%;
}
body{
    margin: 0 0 0 0;
    padding:0 0 0 0;

}
div{
    box-sizing: border-box;-moz-box-sizing: border-box;
    height:100%;
    display: inline-block;
}
body > div:first-child{
    width:20%;
    border:solid 2px green;
}
body > div:nth-child(2){
    width:80%;
    border:solid 2px blue;
    float:right;
}

function alert1(){

document.getElementById("upload_target").innerHTML='<object type="text/html" data="https://www.google.co.in" ></object>';

}
alert1()

Try this one. 试试这个。

 function load_home() { document.getElementById("content").innerHTML = '<object type="type/html" data="home.html" ></object>'; } 
 <div id="topBar"> <a href="#" onclick="load_home()"> HOME </a> </div> <div id="content"></div> 

This is "Cross-Origin Resource Sharing" (unless your page is inside the google.co.in domain). 这是“跨源资源共享”(除非您的页面位于google.co.in域内)。 Long story here: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing 长话在这里: https : //en.wikipedia.org/wiki/Cross-origin_resource_sharing

Your code will work as is using a Url within your own domain. 您的代码将像在您自己的域中使用Url一样工作。 Most sites do not allow it. 大多数网站不允许这样做。 Browsers vary in how tolerant they are of it. 浏览器对容错的方式有所不同。 If the target is in your control you can add the following to the header of the target page to allow it - 如果目标位于您的控件中,则可以将以下内容添加到目标页面的标题中以允许它-

Access-Control-Allow-Origin: *

See this for more. 看到更多。 http://enable-cors.org/server.html http://enable-cors.org/server.html

If not you can proxy the external page serverside with php, node.js or asp, then hit your proxied page for the object's data. 如果不是,则可以使用php,node.js或asp代理外部页面服务器端,然后在代理页面中查找对象的数据。 But that is a whole different topic. 但这是一个完全不同的话题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM