问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/40362093/safari-window-open-doesnt-work