【问题标题】:How to embed div/section of one website如何嵌入一个网站的 div/section
【发布时间】:2018-02-16 03:05:34
【问题描述】:
<html>
<head>
<script  src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>

<body>    

<div id="target-div"></div>
<div id="error"></div>
<div id="success"></div>

<script>

//$('#target-div').load('https://example.com.au');

$( "#success" ).load( "https://example.com.au #divId", function( response, status, xhr ) {
    $( "#success" ).html( response );
  if ( status == "error" ) {
    var msg = "Sorry but there was an error: ";
    $( "#error" ).html( msg + xhr.status + " " + xhr.statusText );
  }
});
</script>

</body>
</html>

我收到了这个回复

抱歉,出现错误:0 错误

我尝试了&lt;iframe&gt;,但整个网站都加载了&lt;iframe&gt;,而我只需要加载特定部分,我尝试了“&lt;iframe&gt; with div id 但没有运气。

【问题讨论】:

    标签: jquery iframe embed


    【解决方案1】:

    由于跨域问题,您很可能无法按照您想象的方式运行,请参阅this answer

    【讨论】:

      猜你喜欢
      • 2021-09-03
      • 1970-01-01
      • 1970-01-01
      • 2021-09-07
      • 1970-01-01
      • 2016-10-05
      相关资源
      最近更新 更多