浏览器 windows.open 弹窗被拦截的解决办法
1
| <a href="javascript:;" onclick="dialog();">点击弹窗</a>
|
1. 使用同步请求
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <script type="text/javascript"> function dialog(){ $.ajax({ url: 'url', type: 'POST', dataType: 'json', async: false, data: {param1: 'value1'}, success: function(data){ window.open("url"); } }) } </script>
|
2. 创建新窗口
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <script type="text/javascript"> function dialog(){ var popup = window.open('about:blank', '_blank'); $.ajax({ url: 'url', type: 'POST', dataType: 'json', async: false, data: {param1: 'value1'}, success: function(data){ popup.location = data.url; } }) } </script>
|