admin管理员组文章数量:1390399
I am sending an email that links a user to a URL with a query string. I am retrieving this string with:
var getQueryString = function ( field, url ) {
var href = url ? url : window.location.href;
var reg = new RegExp( '[?&]' + field + '=([^&#]*)', 'i' );
var string = reg.exec(href);
return string ? string[1] : null;
};
var list = getQueryString('list', window.location.href);
console.log(list);
I want to pass this query string to another link on this page. My current function reads as:
function signin(){
var email = document.getElementById('email').value;
var password = document.getElementById('password').value;
firebase.auth().signInWithEmailAndPassword(email, password).then(function(){
window.location.replace("management.html" + list);
})
.catch(function(error) {
...
});
}
How can I correctly pass the variable list
to signin
?
I am sending an email that links a user to a URL with a query string. I am retrieving this string with:
var getQueryString = function ( field, url ) {
var href = url ? url : window.location.href;
var reg = new RegExp( '[?&]' + field + '=([^&#]*)', 'i' );
var string = reg.exec(href);
return string ? string[1] : null;
};
var list = getQueryString('list', window.location.href);
console.log(list);
I want to pass this query string to another link on this page. My current function reads as:
function signin(){
var email = document.getElementById('email').value;
var password = document.getElementById('password').value;
firebase.auth().signInWithEmailAndPassword(email, password).then(function(){
window.location.replace("management.html" + list);
})
.catch(function(error) {
...
});
}
How can I correctly pass the variable list
to signin
?
2 Answers
Reset to default 3Your list
variable only contains the value of the query '?list=123'
which for example would be '123'
You aren't creating a new query string....just adding that same value to end of the new url so it would look like "management.html123'
If you want the whole query string from current page passed to new page you can use location.search
location.replace("management.html" + location.search);
Or for just the 'list'
do:
location.replace("management.html?list=" + list);
If these are not on the same page and the global variable is not accessible, I would use the local storage solution presented here:
Passing Variable through JavaScript from one html page to another page
本文标签: javascriptHow can I pass a query string to windowlocationreplace()Stack Overflow
版权声明:本文标题:javascript - How can I pass a query string to window.location.replace()? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744734507a2622243.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论