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?
Your 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 you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With