admin管理员组文章数量:1220818
I have this JS code:
window.open(loginurl, '_blank');
coming from a condition for example:
if (userloggedin) {
//popup another page
} else {
window.open(loginurl, '_blank');
}
"loginurl" is an login URL that I would like to open in new window.
Problem: This will be blocked in most browsers (Firefox and Chrome) because it behaves like a popup.
I would like a solution that will still utilizes my login URL variable (not altering the if else statement), open it in new window without any warnings of a popup that is being blocked.
I am searching for ways but I never found a solution. If somebody can provide some tips or insights. That would be highly appreciated.
Thanks.
I have this JS code:
window.open(loginurl, '_blank');
coming from a condition for example:
if (userloggedin) {
//popup another page
} else {
window.open(loginurl, '_blank');
}
"loginurl" is an login URL that I would like to open in new window.
Problem: This will be blocked in most browsers (Firefox and Chrome) because it behaves like a popup.
I would like a solution that will still utilizes my login URL variable (not altering the if else statement), open it in new window without any warnings of a popup that is being blocked.
I am searching for ways but I never found a solution. If somebody can provide some tips or insights. That would be highly appreciated.
Thanks.
Share Improve this question asked Feb 1, 2013 at 9:19 Emerson ManingoEmerson Maningo 2,2699 gold badges33 silver badges48 bronze badges 2- 1 this should not be blocked if a user clicks somewhere on page, e.g. on a link and opens a popup using this link... or you might need to get into some black-hat JS/FLASH hacking – Zathrus Writer Commented Feb 1, 2013 at 9:21
- 2 stackoverflow.com/questions/7139103/… Duplicate question – yajay Commented Jul 2, 2013 at 10:15
2 Answers
Reset to default 12The window opened by window.open
will always be regarded as a pop-up to block by browsers when the function is triggered without a user action initiating it.
That means that for example that these will not be blocked:
$('a').on('click.open', function(e) { e.preventDefault(); window.open('http://disney.com') });
Chrome even allows other events to trigger the popup, while firefox will not allow this:
$(document).on('keydown', function(e) { window.open('http://stackexchange.com') });
And this will be blocked:
$(document).ready(function() { window.open('http://stackoverflow.com') });
So, unless you're triggering the window.open
after a user action, you can never be sure that your window won't be blocked.
This way won't block your popup:
$.ajax({
url:"url",
dataType: "text",
cache: false,
success: function(data){
window.open('url','_self');
}
});
本文标签: javascriptAllow windowopen to open new window and not popupStack Overflow
版权声明:本文标题:javascript - Allow window.open to open new window and not popup - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739264995a2155549.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论