繁体   English   中英

使用屏幕分辨率的Javascript iframe

[英]Iframe with Javascript using Screen Resolution

我有2个web example.com(对于台式机)和example.net(对于移动版)。 我想通过检测屏幕分辨率大小对其进行内嵌。 我正在尝试此代码

<script type="text/javascript">
    if (screen.width <= 720) {
         document.write("<iframe src="http://example.com" width="100%" height="100%" frameborder="0" marginheight="0" marginwidth="0"></iframe>");
    } else {
         document.write("<iframe src="http://example.net" width="100%" height="100%" frameborder="0" marginheight="0" marginwidth="0"></iframe>");
    }
</script>

但是代码无法正常工作,请使用PHP或JavaScript代码帮助我,以使其正常工作。

你可以通过更换试码"'用于向的属性赋予值iframedocument.write("<iframe src='http://example.com' width='100%' height='100%' frameborder='0' marginheight='0' marginwidth='0'></iframe>");

试试这个脚本

<script type="text/javascript">
    if (screen.width <= 720) {
     document.write('<iframe src="http://example.com" width="100%" height="100%" frameborder="0" marginheight="0" marginwidth="0"></iframe>');
    } else {
     document.write('<iframe src="http://example.net" width="100%" height="100%" frameborder="0" marginheight="0" marginwidth="0"></iframe>');
    }
</script>

小提琴

暂无
暂无

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

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