![](/img/trans.png)
[英]Problem using Javascript to redirect to a URL with a query string
[英]Retrieve url query string using javascript to resolve a if/else statement and redirect
我在這里閱讀了有關該主題的其他6篇文章,但似乎仍然無法使它起作用。
我想使用純JavaScript來讀取用戶定義的url查詢字符串,然后讓它根據字符串中的信息來決定將用戶重定向到何處。
我將JavaScript保存在“ script.js”中,這是網頁“ https://www.website.com/script.js ”的一部分,帶有查詢字符串的網址看起來像這樣“ https:// www .website.com / script.js?bird = chicken ”。
這是我的代碼如下所示:
}
var birdtype = getQueryString('bird');
if ( birdtype == [ chicken ])
window.location.replace = "https://www.website.com/chicken.html";
else
window.location.replace = "https://www.website.com/turkey.html";
};
拜托,我在做什么錯?
您可以使用.href屬性,而不是使用諸如window.location.href = "https://www.website.com/chicken.html"
類的替換來重定向到其他頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.