window.location.href和window.open相互阻止?

时间:2016-05-26 16:03:14

标签: javascript jquery ajax

我正在尝试在新网址中打开pdf,并将用户重定向到主页。但是这些“if”块的2.和3.行阻止了彼此。页面重定向到主页但window.open()无效。

 if(result.status == 'success'){
      hideSplashScreen();
      window.location.href = webContextPath+"/user/userhome";
      window.open(result.message, '_blank').focus();
 }

2 个答案:

答案 0 :(得分:2)

实际上window.location.href = webContextPath+"/user/userhome";离开当前页面,所以window.open可能永远不会运行...

您是否尝试过先调用window.open(result.message, '_blank').focus();,然后才调用window.location.href = webContextPath+"/user/userhome";

答案 1 :(得分:1)

翻转序列:首先调用window.open(result.message,'_ blank')。focus();第一

if(result.status == 'success'){
      hideSplashScreen();
      window.open(result.message, '_blank').focus();
      window.location.href = webContextPath+"/user/userhome";
 }