html 当此特定链接加载到移动的上时,我如何发送警报?

wljmcqd8  于 2023-02-14  发布在  其他
关注(0)|答案(1)|浏览(95)

我正在为一个小游戏制作网站。网站的索引页可以在here找到。视频页面在移动的上无法正常工作,我想在加载视频页面时显示警报。
这是我得到的:

window.onload = function () {
      if (document.url == "https://tfojofficialwebsite.glitch.me/videos.html") {
    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/i) ||
      navigator.userAgent.match(/Windows Phone/i)
    ) {
      console.log("true");
      alert("This page may not work properly on your device.");
    } else {
      console.log("false");
    }
  }
};

我期待的是当页面加载到移动的上时会有一个提醒,但是它什么也不做,不管是不是移动设备。我搞砸了什么?

dnph8jn4

dnph8jn41#

我注意到您的代码运行不正常。问题似乎与

document.url

此属性未定义,但可以通过使用

if (window.location.href == "https://tfojofficialwebsite.glitch.me/videos.html")

这是一个简单的更改,应该可以解决代码中的问题。

相关问题