2016-06-10 54 views
0

其他尝试在此脚本中使用window.open('url', '_blank')可按需要工作。这一个,不打开新标签,在confirm()提示符后面使用不同的逻辑。如果在其中找到“保留”或者重定向到目标页面,逻辑是显示页面的一部分。追踪为什么window.open不起作用

作为$.ajax成功处理程序的结果,重定向是自动的。重定向的两种方法都不做任何更改。

形式第2种方法:

<form method=\"get\" id=\"formgoregistry\" name=\"goregistry\" action=\"\" target=\"_blank\"> 
</form> 

javascript函数的问题:

function getRegistryInfo(num) { 
    // for 2nd method, set the form's action 
    $('#formgoregistry').attr('action', 'http://somesite.com/somefile?n=somevalue'); 

    var response = $.ajax({ 
     type: 'POST', 
     url: 'purchases_registry.php', 
     dataType: 'html', 
     data: { number: num }, 
     success: function(data) { 
      console.log('response = '+data); 
      if (data.indexOf('Reserved') > 0) { 
       // work with the result 
       // Code in here works fine 
       .... 
      } 
      else { 
       // wrong data, redirect to outside page 
       // ** Neither of these method open a new tab 
       // 1st method 
       var url = 'http://somesite.com/somefile?n=somevalue'; 
       console.log('url = '+url);    // prints the correct url 
       var w = window.open(url, '_blank');  // NO new tab or error 
       console.log('window = '+w);    // window = undefined 

       // 2nd method (setting form's action beforehand) 
       console.log(document.goregistry.action); // prints the correct url 
       document.goregistry.submit();    // NO new tab or error 
      } 
     } 
    }); 
} 

我想知道如果未在所述窗口的问题和原因的一部分。

回答

0

使用该脚本打开新窗口的链接:

echo "<form action=\"your_link.php?id=\" method=\"post\" target=\"myWindow\", onsubmit=\"window.open('', this.target, 'width=300,height=400,resizable=no,scrollbars=no');return true;\"> 

或HTML语言:如果您在使用A HREF方法只是单纯的onsubmit到的onclick改变

<form action="your_link.php?idk=$id=" method="post" target="myWindow", onsubmit="window.open('', this.target, 'width=300,height=400,resizable=no,scrollbars=no');return true;"> 

,这就是我知道,希望它有帮助,祝你好运!

+0

提交需要用JavaScript。 'window.open('url');'或'document.goregistry.submit();' – David