Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获检测移动与桌面和URL_Javascript_Variables_Url_Iframe_Browser Detection - Fatal编程技术网

Javascript 未捕获检测移动与桌面和URL

Javascript 未捕获检测移动与桌面和URL,javascript,variables,url,iframe,browser-detection,Javascript,Variables,Url,Iframe,Browser Detection,我似乎无法检测到用户代理。我的URL没有正确加载iframe <iframe id="link" width="100%" height="300"> <p>Your browser does not support iframes.</p> </iframe> 小提琴- 救命啊 当页面成功加载时,您需要这样做。试试这个 window.onload=转换; 函数convert(){ if(navigator.userAgent.match

我似乎无法检测到用户代理。我的URL没有正确加载iframe

<iframe id="link" width="100%" height="300">
  <p>Your browser does not support iframes.</p>
</iframe>

小提琴-


救命啊

当页面成功加载时,您需要这样做。试试这个


window.onload=转换;
函数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(/windowsphone/i)|
navigator.userAgent.match(/ZuneWP7/i))
{
变量url4=”http://news.ycombinator.com";
}否则{
var url4=“lol.png”;
}
document.getElementById(“link”).src=url4;
//convert();
}

您没有调用脚本。尝试:


您的浏览器不支持iFrame

函数转换(){ 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(/windowsphone/i)| navigator.userAgent.match(/ZuneWP7/i) ) { url=”http://news.ycombinator.com"; } document.getElementById(“link”).src=url; } 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>
     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>
<!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>