window.open弹出窗口在单击事件期间被阻止 [英] window.open popup getting blocked during click event
问题描述
我最终需要做的是运行 $。ajax()
调用,然后运行,打开一个新窗口。
What I ultimately need to do is run an $.ajax()
call and then after that is run, open a new window.
使用点击预览按钮保存当前表单,然后打开一个新窗口,显示项目的预览以及刚刚保存的数据。
A use clicks on a "Preview" button that saves their current form then opens a new window that shows a preview of the item with the data that was just saved.
但按原样,弹出窗口拦截器会阻止 window.open
函数。
But as-is, the window.open
function gets blocked by popup blockers.
以下是我的代码的基本部分:
Here's the basic parts of my code:
HTML:
<a href="/surveys/185/preview" class="preview" target="_blank">Preview</a>
JavaScript:
JavaScript:
$('.preview').live('click', function(event){
save_survey($(this).attr('href'));
event.preventDefault();
});
function save_survey(url) {
$.ajax({
type: "POST",
url: form_url,
dataType: 'json',
data: form_data,
success: function(data) {
window.open(url, '_blank');
}
});
}
推荐答案
我最近遇到过这个问题并发现这个解决方法:
I ran into this problem recently and found this work-around:
1)在调用之前调用
并保存窗口参考: window.open
$ .ajax
1) call window.open
just before calling $.ajax
and save window reference:
var newWindow = window.open(...);
2)回调集 location
属性保存的窗口参考:
2) on callback set location
property of the saved window reference:
newWindow.location = url;
也许它对你有帮助。
这篇关于window.open弹出窗口在单击事件期间被阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!