iframe如何设置无边框自适应高度

如何让xxx.com的首页是yyy.com的首页,他的思路是用iframe,好吧,我们就用他的。如何实现完整的调用的。
方法一:

<iframe src="https://****.cn" id="myiframe" scrolling="yes" frameborder="0" width="100%"></iframe>
<script type="text/javascript">
var ifm = document.getElementById("myiframe");
ifm.height = document.documentElement.clientHeight;
</script>

方法二:

<iframe src="http://www.bingdou.com.cn" style="width:100%;height:1100px" name="iframe_a" frameborder="no" id="ifr" border="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="yes"></iframe> 
<script>
// 计算页面的实际高度,iframe自适应会用到
function calcPageHeight(doc) {
var cHeight = Math.max(doc.body.clientHeight, doc.documentElement.clientHeight)
var sHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight)
var height = Math.max(cHeight, sHeight)
return height
}
window.onload = function () {
var height = calcPageHeight(document)
parent.document.getElementById('ifr').style.height = height + 'px'
}
</script>

顺便附一个用php获取其他网站内容的方法

<?php
$homepage = file_get_contents('https://****.cn/');
echo $homepage;
?>

php的话也可以使用curl
jq的话,可以用load的方法

© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享
相关推荐
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容