0

Hi I am using a href code to make a image button. Can anyone tell me how to add a secondary action to the button mainly 2 url triggers on click.

My example is fairly easy

<a> href="example.com"><img src="source-image.png" /></a>

So the current page goes to the new URL in its current window, but a new window opens with another Url for payment method.

Can it be done??

Progman
  • 16,827
  • 6
  • 33
  • 48
  • 1
    Does this answer your question? [Open multiple links in Chrome at once as new tabs](https://stackoverflow.com/questions/24364117/open-multiple-links-in-chrome-at-once-as-new-tabs) – Progman Jul 26 '21 at 19:38
  • Try [window.open()](https://www.w3schools.com/jsref/met_win_open.asp) to open new window with the new url when the link clicked and keep your link href like who is – JS_INF Jul 26 '21 at 19:43

1 Answers1

0
  • use window.open() or shortly open() method which will popup new window with presented uri
  • also becareful because in your html you closed a tag before adding href attribute

Html

<a href="example.com" id="elem">
  <img src="source-image.png" />
</a>

JS

var elem = document.getElementbyId("elem");
elem.addEventListener("click", function () {
    window.open("https://developer.mozilla.org");
});
JS_INF
  • 467
  • 3
  • 10