javascript - Open window in new tab without user event -


here have 2 asp.net mvc websites . first website have 1 link second website. first website call second's action. want open on page in new tab , current tab should redirect first website. action return 1 view.

my approaches in view

1.

$(document).ready(function (e) {     window.open("/newpage");     window.open("/site1", "_self");  }); 

browser popup blocker block this. because there no user event . tried different approach

2.

$(document).ready(function (e) {        $("#input").on("click", function () {         window.open("/newpage");         window.open("/site1", "_self");     });     $("#input").trigger("click"); });  <label id="input" style="display:none;">test one</label> 

i have triggered 1 event. still blocked. 2 approaches working fine if popup blocker disabled. want open page in new tab without disable popup blocker.

note: 2 website comes under same domain name . eg: abc.com\siteone , abc.com\sitetwo

from first website have 1 link second website. first website call second's action. want open on page in new tab , current tab should redirect first website.

the way i've done once or twice had use case use link element click handler: click handler opens new window, , link element's default action follows link, taking existing window new location. way, is user-initiated action. works in every browser i've tried in. should note tends not work in things jsfiddle or jsbin, because of how wrap things.

so in case, link's href want them go on first website, , window.open second website.

example:

<!doctype html> <html> <head> <meta charset="utf-8"> <title>double</title> <style> body {   font-family: sans-serif; } </style> </head> <body> <a href="http://stackoverflow.com">click me</a> <script> document.queryselector("a").addeventlistener(     "click",     function() {         window.open("http://google.com");     },     false ); </script> </body> </html> 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -