Wednesday, June 25, 2014

Opening new window/tab without using `window.open` or `window.location.href`


Answer from stackoverflow.com:

What it does:
  1. Create a form
  2. Give it attributes
  3. Append it to the DOM so it can be submitted
  4. Submit it
  5. Remove the form from the DOM
Now you have a new tab/window loading "https://google.nl" (or any URL you want, just replace it). Unfortunately when you try to open more than one window at once this way, you get an Popup blocked messagebar when trying to open the second one (the first one is still opened).
Source Code:

var form = $("<form></form>");
form.attr(
{
    id     : "newform",
    action : "https://google.nl",
    method : "GET",
    target : "_blank"        // Open in new window/tab
});

$("body").append(form);
$("#newform").submit();
$("#newform").remove();

No comments:

Post a Comment