為何我的 iframe 在此程式碼段中無法載入?
P粉514458863
P粉514458863 2023-09-15 11:06:40

所以我這裡有一小段程式碼,用來偵測是行動瀏覽器還是桌面瀏覽器。這個功能是有效的,但是我嘗試根據瀏覽器提供不同的iframe,但是iframe沒有加載。請幫忙修復!

<html>
<body>
    <script>
        /* 将用户设备信息存储在一个变量中 */
        let details = navigator.userAgent;
  
        /* 创建一个包含一些移动设备关键词的正则表达式,
        用于在details字符串中搜索 */
        let regexp = /android|iphone|kindle|ipad/i;
  
        /* 使用test()方法在details中搜索regexp,
        它返回一个布尔值 */
        let isMobileDevice = regexp.test(details);
  
        if (isMobileDevice) {
            document.write("您正在使用移动设备");
        } 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版本,但沒有成功。請幫忙!

P粉514458863
P粉514458863

全部回覆(1)
P粉785905797

如果設備偵測到使用者代理程式是行動設備,則會顯示不相容的裝置訊息,否則將繼續瀏覽器活動,即使他們在行動瀏覽器中啟用了桌面模式,仍然會顯示不相容的訊息





而且你可以使用三元運算子來取代IF ELSE語句。

isMobile ? message() : browser();
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!