通过JavaScript代码重定向后,Shopify页面不断刷新

发布于 2025-02-12 14:26:22 字数 649 浏览 0 评论 0原文

我正在尝试创建一个网站 https://fone-kase-plus.myshopify.com/ 将检测到从哪个设备模型(例如Galaxy A40)访问的设备模型,因此它将立即将用户重定向到相应的页面。 它似乎正在工作,但是重定向后会多次重新加载页面。如果我尝试将其重定向到非交换页面(例如Stackoverflow.com),则不会发生此问题。

function deviceAPIcallback(result){ if(result.deviceName == "desktop"){ window.location.href = "https://fone-kase-plus.myshopify.com/pages/galaxy-a40"; } else{ alert(result.deviceName); } }

您能告诉我问题是什么,或者至少我如何通过开发工具检测到它? 谢谢

I am trying to create a website https://fone-kase-plus.myshopify.com/ that will detect what device model it's being accessed from (for example GALAXY A40) so it will immediately redirect the user to a corresponding page.
It seems to be working, but it will reload the page multiple times after redirecting. If I try to redirect it to non-shopify page (eg stackoverflow.com) this problem doesn't occur.

function deviceAPIcallback(result){

if(result.deviceName == "desktop"){
window.location.href = "https://fone-kase-plus.myshopify.com/pages/galaxy-a40";
}

else{
alert(result.deviceName);
}

}

Can you please tell me what the problem can be or at least how I can detect it by dev tools?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

德意的啸 2025-02-19 14:26:22

当我从MacOS笔记本电脑和iPhone访问网站时,我只会获得您功能的警报方面。 result.devicename返回什么?如果'语句,您可能需要将第三个'='添加到您的第一个''中。

function deviceAPIcallback(result) {
    if(result.deviceName === "desktop") {
        window.location.href = 'https...';
    } else { 
        alert(result.deviceName);
    }
}

When I go to the site from both my macOS laptop and my iPhone I only get the alert aspect of your function. What does result.deviceName return? You might need to add a third '=' to your first 'if' statement.

function deviceAPIcallback(result) {
    if(result.deviceName === "desktop") {
        window.location.href = 'https...';
    } else { 
        alert(result.deviceName);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文