Window.Open(Url, '_Blank'); Not Working on Imac/Safari

window.open('', '_blank') doesn't open new tab on iOS only

I haven't tried this before, but implementing the solution from the SO answer would look like this:

// Open a new window and save a reference to it
var newWindow = window.open();

const addProducts = (products) => {
setProductsAdded(false);
cService
.add(products)
.then(() => {
setLoading(null);
setProductsAdded(true);

// Set the URL of the new window
newWindow.location = C_LINK;
})
.catch(() => {
setError('Error');
});
};

In the other post, myService is a non-existent, example service that returns a URL.

Javascript window.open issue in safari

I have found alternate solution for this. After ajax response create anchor tag element and trigger click event

 var a = document.createElement('a');
a.href = 'https://google.com';
a.setAttribute('target', '_blank');
a.click();

Open new window after a click event not working in Safari, Chrome

Safari/Chrome have built-in pop-up blockers that stop this from working. The only javascript that is allowed to open a new window in Safari/Chrome is javascript directly attached to click handlers (and other direct user input handlers). In past versions people figured out some ways to cheat (like generating some other element -- a form or div -- and simulating user input with javascript), but newer versions are smarter about detecting this. I'd recommend re-configuring things so that you don't use a delayed pop-up -- that is the kind of thing that can generally be jarring to a user after all.

javascript. Can't open new tab in safari

It turns out it's a browser preference, which can be edited under Edit -> Preferences -> Tabs and select the Automatically option in the drop-down menu Open pages in tabs instead of windows.

Open formatted URL in new tab JS

To open a new window/tab you should use window.open() just like that:

function viewSource(){  var webcache = "http://webcache.googleusercontent.com/search?q=cache:";  var request = "&prmd=ivn&strip=0&vwsrc=1";  var url = window.prompt("Enter valid URL");    const Link=webcache+url+request;    //Check for myService object (Refers to iMac/Safari)  if(typeof myService!="undefined"&&typeof myService.getUrl!="undefined"){    const windowReference = window.open();    myService.getUrl().then(function(url) {         windowReference.location = Link;    });  //Otherwise, we can just open a normal window ( Chrome, Firefox, ..)  }else window.open(Link, '_blank');  return Link;}
<button onclick="viewSource();">Open Link</button>


Related Topics



Leave a reply



Submit