admin管理员组文章数量:1201372
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?
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?
Share Improve this question asked Nov 1, 2016 at 14:26 francescafrancesca 5873 gold badges10 silver badges21 bronze badges2 Answers
Reset to default 17The 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
If you want to open a popup window in the Safari browser, you need to follow the below code. Open popup window before getting URL from the backend.
const width = 500;
const height = 600;
const top = window.innerHeight / 2 - height / 2;
const left = window.innerWidth / 2 - width / 2;
const params = `modal=yes, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${width}, height=${height}, top=${top}, left=${left}`;
if (oauthPopup === null || oauthPopup.closed) {
console.log(oauthPopup);
oauthPopup = window.open("", "", params);
}
After getting a URL from the backend, change the location of the popup window.
await request()
.get(`/sources/authorizationEndpoint`, {
headers: {
authorizer: token,
},
})
.then((response) => {
const url = response.data.oauth_url;
oauthPopup.location = url;
oauthPopup.focus();
})
.catch((err) => {
oauthPopup.close();
});
本文标签: javascriptSafari windowopen() doesn39t workStack Overflow
版权声明:本文标题:javascript - Safari window.open() doesn't work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738633318a2103879.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论