We also had a similar requirement. We wanted to generate a server-side href url using an ajax call when the user clicks on it. after repeated searches, we found out that it is actually controlled by the browser. In chrome, a newly opened page opens as a popup and is blocked by a popup blocker. Most users of our application were confused by this behavior. This is the workaround we used. Hope this helps someone who has a similar issue.
We may have a regular link that points to the actual web page that we have on our site called LandingPage.html. We must set the target to "_blank" to open a window on the same browser tab.
<a href="LandingPage.html" id="fakeLink" target="_blank">Click to open google in the same browser window</a>
Then we join the click event of the fakeLink binding element.
$('#fakeLink').click(function(){ $.ajax({ url: "" }).done(function() { localStorage.setItem('url', 'https://www.google.lk'); }); });
We can make an ajax call and get the dynamically generated URL from the server. then we can add this url to localstorage.
The landing page may have text that tells users that they will be redirected in a second. "You will be redirected to google in 1 second."
On the landing page, we can have a setting parameter, and inside this function, we can use window.location to redirect the user to the actual page.
setTimeout(function(){ window.location.assign(localStorage.getItem('url')); }, 1000);
Hope this helps.This should work in all browsers, I only tested in IE 10 and Chrome, since we do not use any actions related to the browser.
Nuwan
source share