Snowshoot
Snowshoot

Reputation: 183

HTML a href with target set to "_blank" without moving to the opened page

I would want to create an tag with target attribute set to blank, but without actually moving me to the opened page, but rather staying on the page it was opened on.

Upvotes: 1

Views: 1132

Answers (2)

Iman Emadi
Iman Emadi

Reputation: 420

following JS code below opens a new window on your current window and user remains on the first page yet

  window.open("https://www.w3schools.com", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");

Upvotes: 0

Space
Space

Reputation: 39

I hope this helps.

<!DOCTYPE html>
<html>
   <head>
      <title>Page Title</title>
      <style></style>
   </head>
   <body>
      <a href="https://google.com/" trueblank="true" >Click Me</a>
      <script>
         var links = document.querySelectorAll("a");
         links.forEach(function(each) {
            each.onclick = function(ev) {
                if(this.getAttribute("trueblank") == "true") {
                    ev.preventDefault();
                    window.open(this.href);
                 }
             }
         });
      </script>
   </body>
</html>

Upvotes: 2

Related Questions