B
B
BohdanchukVL2018-12-26 19:00:55
JavaScript
BohdanchukVL, 2018-12-26 19:00:55

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

1 answer(s)
V
Vitaliy Orlov, 2018-12-26
@BohdanchukVL

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');
    }
})

and you can dynamically generate a link like this
let url = document.location.href + '#btn';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question