[英]Detecting Mobile VS Desktop and URL is not captured
我似乎無法檢測到用戶代理。 我的網址無法正確加載iframe。
<iframe id="link" width="100%" height="300">
<p>Your browser does not support iframes.</p>
</iframe>
function convert() {
if (navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPad/i) ||
navigator.userAgent.match(/iPod/i) ||
navigator.userAgent.match(/BlackBerry/) ||
navigator.userAgent.match(/Windows Phone/i) ||
navigator.userAgent.match(/ZuneWP7/i)
) {
var url4 = "http://news.ycombinator.com";
}
else {
var url4 = "lol.png";
}
document.getElementById("link").src=url4;
convert();
}
小提琴-http: //jsfiddle.net/DnRH3/
救命!
成功加載頁面后,您需要執行此操作。 試試這個小提琴吧 。
<script>
window.onload = convert;
function convert() {
if (navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPad/i) ||
navigator.userAgent.match(/iPod/i) ||
navigator.userAgent.match(/BlackBerry/) ||
navigator.userAgent.match(/Windows Phone/i) ||
navigator.userAgent.match(/ZuneWP7/i))
{
var url4 = "http://news.ycombinator.com";
} else {
var url4 = "lol.png";
}
document.getElementById("link").src=url4;
//convert();
}
</script>
您沒有在調用腳本。 嘗試: http : //jsfiddle.net/DnRH3/2/
<!DOCTYPE html>
<html>
<head></head>
<body>
<iframe id="link" width="100%" height="300">
<p>Your browser does not support iframes.</p>
</iframe>
<script>
function convert() {
var url = "lol.png";
if (navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPad/i) ||
navigator.userAgent.match(/iPod/i) ||
navigator.userAgent.match(/BlackBerry/) ||
navigator.userAgent.match(/Windows Phone/i) ||
navigator.userAgent.match(/ZuneWP7/i)
) {
url = "http://news.ycombinator.com";
}
document.getElementById("link").src = url;
}
window.onload = convert;
</script>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.