繁体   English   中英

跟踪为什么window.open不起作用

[英]Track down why window.open does not work

根据需要尝试在此脚本中使用window.open('url', '_blank')其他尝试。 这个,而不是打开新的选项卡,在confirm()提示后使用不同的逻辑。 逻辑是在页面中找到“保留”时显示页面的一部分,否则重定向到目标页面。

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

第二种方法的表格:

<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
            }
        }
    });
}

我想知道是否未定义窗口是问题的一部分,为什么。

使用此脚本在新窗口中打开链接:

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语言:

<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;">

如果您使用href方法,只需将onsubmit更改为onclick,这就是我所知道的,希望对您有所帮助,祝您好运!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM