I have 2 web example.com (For Desktop) and example.net (For Mobile). 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.
你可以通过更换试码"
与'
用于向的属性赋予值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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.