1

On my site I created several href buttons, I want these different buttons to lead to the same page but with an additional js action. As when I click on the first link, this brings me to the page so and the second leads to the same page but with a javascript action activated.

I hope I have been clear enough and that this is possible, thank you for your response.

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182

3 Answers3

0

adding a class/id to it would help I think. I'm new here so let me know if that's what you are looking for

<a class="script" href="...">Link</a>

then in your javascript, you can manipulate it

var link = document.querySelector(".script");

link.addEventListener("click", function(){

    // your function here

});
0

You can make this happen by sending url parameters with each href button: /page.html?action=1 . See parsing url parameters in javascript

Next on page.html use the following javascript:

window.onload = function() {
    let url = new URL(window.location.href);
    let action = url.searchParams.get("action");
    if (action == "1") {
        //perform an action
        action1();
    } else if (action == "2") {
        action2();
    }

};

Chiel
  • 1,324
  • 1
  • 11
  • 30
0

Basically, I have a page where there are buttons that lead to another page or there are buttons that make things happen in js, and I want that when we click the button on the first page, we arrives on the second page when js is activated. Basically I explain my site I have a button "visual identity" which should lead to another page (easy), on this second page there is sub-buttons like "fish" which display a menu with js commands, its sub-buttons are also on the first page and I want when you click on the sub-button on the first page it will take you to the second page with menu opening. I don't know if that's what you understood just above? but thanks for your reply.