Answer the question
In order to leave comments, you need to log in
How to set a parameter in a URL?
Good afternoon
I have a page with a conditional button. And I want to formulate a URL so that when you click on it, the page is loaded and the button is pressed (or the function that clicks on it is executed). How can this be done?
Answer the question
In order to leave comments, you need to log in
google window.location.hash
with it, you can read the parameter btn from the url of the view,
then it remains only at the time of page load to check whether there is such a parameter or not and do the necessary actions, something like this
window.addEventListener('load', function() {
if (location.hash=='#btn') {
console.log('Press btn');
}
})
let url = document.location.href + '#btn';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question