我试图在我的网页中显示一个包含文本框和按钮的 div。
div 不在我的服务器中,是第三方网站,我无权修改基本代码。
这是可能的???这是我想在我的网站上显示的代码,来自第三方网站。
div标签id是“body”
<div id="body">
<h2>Consulta de Teléfonos Robados o Bloqueados por IMEI</h2><div style="width:100%; height:auto;">
<script type="text/javascript">
function buscar(keyWords){
jQuery(document).ready(function($){
$.post('../../../bdtronline/sistema/areas.php',{
accion:'searchImei',
keyWords:keyWords},
function(data){$('#listImeiFound').html(data);});
});
}
</script>
<form>
Buscar <input type="text" id="keyWords" name="keyWords" size="50" /><input type="button" value="buscar" onclick="buscar(document.getElementById('keyWords').value);" />
</form>
</body>
最佳答案
如果在运行 JavaScript 的服务器上运行 PHP,则可以加载服务器页面,通过 PHP 从其他域获取页面内容:
proxy.php
:
<?php
$opts = array('http' =>
array(
'method' => 'POST',
'header' => "Content-Type: application/x-www-form-urlencoded",
'content' => http_build_query($_POST)
)
);
$context = stream_context_create($opts);
echo file_get_contents('http://php.net/manual/en/function.file-get-contents.php', false, $context);
yoursite.html
// ...
jQuery(document).ready(function($){
$.post('proxy.php',{
accion:'searchImei',
keyWords:keyWords},
function(data){$('#listImeiFound').html(data);});
});
});
// ...
关于html - 从外部第三方网页嵌入 <div>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24829822/