1. 程式人生 > >window.open被攔截

window.open被攔截

攔截 strong 調用 簡單 res window func pre style

1)直接調用window.open 或 點擊的時候直接調用 window.open 是不會被攔截的

// 不會被攔截
$(‘.btn-open‘).click(function(){ window.open(‘xxxx‘, ‘_blank‘); });

2)window.open 只能放函數第一層,放在函數嵌套裏會被攔截

// 會被攔截
$(‘.btn-open‘).click(function(){ $.get(‘xxxx.php‘, function(res){ window.open(res.url, ‘_blank‘); }, ‘json‘); });

簡單來說,要想不被攔截,window.open 只能放函數第一層,不能放嵌套函數裏(PS:寫成一個獨立的函數,但調用是在嵌套函數裏調用也是不行的

// 會被攔截
function
openUrl(url){ window.open(url, ‘_blank‘); } $(‘.btn-open‘).click(function(){ $.get(‘xxxx.php‘, function(res){ openUrl(res.url); }, ‘json‘); });

window.open被攔截