Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari window.open() doesn't work

I need to open external link in a new window. I handle click on edit button in a view:

module.exports = utils.Backbone.View.extend({
    events: {
        "click #edit": "onEditClicked"
    },

    "onEditClicked": () => PubSub.publish("EDITOR_REQUESTED");
});

Then I check if the user is logged in. If yes - I send notification "OPEN_EDITOR" and expect a new window to be open with the external link.

TextEditorController.prototype.handleMessages = function () {

    PubSub.subscribe("OPEN_EDITOR", () => {
        var editor = window.open(this.$service.getEditorURL());
    });
});

But in Safari new window seems to be blocked? Is there workaround in my case?

like image 537
francesca Avatar asked Nov 01 '16 14:11

francesca


People also ask

Does window open work in Safari?

If you put window. open in a function and call the function with onclick , Safari will not open a new tab. The function must be inside the to click element. A minor correction to the answer: <button onclick='window.

How do I open a new window in Safari?

In the Safari app on your Mac, drag the tab over the desktop or choose Window > Move Tab to New Window. You can also drag the tab of one Safari window to the tab bar of another.

How many mandatory parameters does the open () method of window does object accept?

open(): This method is used to open the web pages into a new window. Parameters: This method accepts four parameters as mentioned above and described below: URL: It is an optional parameter.


1 Answers

The reason of it is Safari's built-in pop-up blockers.

The only javascript that is allowed to open a new window in Safari - is javascript directly attached to user's event. In your case, you're calling window.open later.

The workaround here can be:

  • to create a window without a URL in onEditClicked method

    safariWindow = window.open();

  • change that window's URL in handleMessages function

    safariWindow.location.href = newUrl

like image 87
Peter Tristianche Avatar answered Oct 28 '22 12:10

Peter Tristianche