【发布时间】:2022-11-23 21:22:02
【问题描述】:
所以我这里有一些代码可以检测它是移动浏览器还是桌面浏览器。这行得通,但我正在尝试根据浏览器提供不同的 iframe,但 iframe 未加载。请帮助/修复!
<html>
<body>
<script>
/* Storing user's device details in a variable*/
let details = navigator.userAgent;
/* Creating a regular expression
containing some mobile devices keywords
to search it in details string*/
let regexp = /android|iphone|kindle|ipad/i;
/* Using test() method to search regexp in details
it returns boolean value*/
let isMobileDevice = regexp.test(details);
if (isMobileDevice) {
document.write("You are using a Mobile Device");
} else {
<iframe target="_parent" src="https://google.com/" style="position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;"></iframe>
}
</script>
</body>
</html>
我尝试了 PHP 版本,但没有成功。请帮忙!
【问题讨论】:
-
您已将 iFrame 的 html 标记包含在 javascript 中。您需要通过
document.createElement()或innerHTML在 JS 中构建它,或者您可以将它隐藏在您的 html 中并使用 JS 来显示它。
标签: javascript html