V
V
vladislav9972020-04-28 10:56:18
JavaScript
vladislav997, 2020-04-28 10:56:18

How to open the current page in a new tab, and in the old another?

Tell me how, when you click on a link, open the current page in a new tab, and another one in the old one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2020-04-28
@vladislav997

It can be something like this:

const link = document.querySelector('a.some-link'); // подставьте свой селектор
link.addEventListener('click', event => {
  event.preventDefault();
  window.open(location.href);
  location.assign(link.href);
});
But this behavior is unexpected for the user. And the state of the page in the new tab will be like when loading.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question