[英]Iframe with Javascript using Screen Resolution
I have 2 web example.com (For Desktop) and example.net (For Mobile). 我有2个web example.com(对于台式机)和example.net(对于移动版)。 I want to iframe it with detection of screen resolution size. 我想通过检测屏幕分辨率大小对其进行内嵌。 I'm trying this code 我正在尝试此代码
<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>
But the code is not working, Please help me with PHP or JavaScript code to make it work. 但是代码无法正常工作,请使用PHP或JavaScript代码帮助我,以使其正常工作。
你可以通过更换试码"
与'
用于向的属性赋予值iframe
像document.write("<iframe src='http://example.com' width='100%' height='100%' frameborder='0' marginheight='0' marginwidth='0'></iframe>");
Try this script 试试这个脚本
<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.