【发布时间】:2015-04-17 15:12:14
【问题描述】:
我正在尝试在页面加载时将此特定字符串添加到我的网址末尾:
?aa_campaign=f45632
(http://examplesite.com/test.html)
用于营销和跟踪。
我试过这个:
if window.location.href.indexOf("http://examplesite.com/test.html") {
window.location = "http://examplesite.com/test.html?aa_campaign=f45632";
}
直截了当没有用,但我正在寻找这个想法。有什么想法吗?
【问题讨论】:
-
那将是一个无限重定向循环。您重定向到的 URL 仍然与 indexOf 检查相匹配
-
我已经更新了我的答案,它应该可以满足您的需求。
-
看起来你是 if 之后的左括号和第一行第一个 { 之前的匹配右括号。应该是这样的:
if (window.location.href.indexOf("http://examplesite.com/test.html"))
标签: javascript jquery url