所以我這裡有一小段程式碼,用來偵測是行動瀏覽器還是桌面瀏覽器。這個功能是有效的,但是我嘗試根據瀏覽器提供不同的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版本,但沒有成功。請幫忙!
如果設備偵測到使用者代理程式是行動設備,則會顯示不相容的裝置訊息,否則將繼續瀏覽器活動,即使他們在行動瀏覽器中啟用了桌面模式,仍然會顯示不相容的訊息
而且你可以使用三元運算子來取代IF ELSE語句。