PHP如何实现嵌入网页功能思路

来源:互联网 发布:郑州婚纱摄影知乎 编辑:程序博客网 时间:2024/06/05 18:04

1、首先生成需要展示的html静态页面。
2、我们可以使用

<?phpheader("Content-Type:text/html;charset=GB2312");if (empty($_GET['suid'])){    exit('地址错误');?>return;<?php }else{    $suid = intval($_GET['suid']);    ?>function setIframeHeight(id){    try{        var iframe = document.getElementById(id);        if(iframe.attachEvent){            iframe.attachEvent("onload", function(){                iframe.height =  iframe.contentWindow.document.documentElement.scrollHeight+20;            });            return;        }else{            iframe.onload = function(){                iframe.height = iframe.contentDocument.body.scrollHeight+20;            };            return;                         }         }catch(e){       // throw new Error('setIframeHeight Error');    }}window.onload = function(){var scripts = document.getElementsByTagName("script");var target = null;var script;var iframeId = 'frameObj';var scriptURL = 'creiframe.php?suid=<?php echo $suid?>';for (var i = 0; i < scripts.length; i++) {    script = scripts[i];    //使用随机数为了防止iframe缓存,到时修改了内容无法立刻显示。    if (script.src.indexOf(scriptURL)>-1) {//这里查找对应的<script>标签        script.outerHTML = "<iframe id='" + iframeId + "' src='http://localhost/survey/<?php echo $_GET["suid"]?>.html?<?php echo rand(1,20)?>' width='100%' height='400'  frameborder=0 allowTransparency='true'>";        setIframeHeight(iframeId);//该函数设置iframe高度        break;    }}}<?php }?>

写好之后将此代码复制到富文本编辑器中,然后就可以实现嵌入网页的功能了

<script type="text/javascript" src="http://localhost/survey/creiframe.php?suid=4"></script>
原创粉丝点击