Javascript 如何重定向到需要带有参数的帖子的外部站点?

Javascript 如何重定向到需要带有参数的帖子的外部站点?,javascript,Javascript,其他要求: 让它变得通用 在新选项卡中打开它 使用IE11在新选项卡中打开它(更难) 将其发布到外部/其他域 问题在于,我们无法在IE11中跨域发布到命名选项卡中 相反,让我们创建一个文件,该文件将使用查询字符串params构建表单 现在只需向该文件发出get请求 首先,使用以下代码创建一个名为postdirect.htm的文件: <!DOCTYPE html> <html> <head> <title></title> &l

其他要求:

  • 让它变得通用
  • 在新选项卡中打开它
  • 使用IE11在新选项卡中打开它(更难)
  • 将其发布到外部/其他域

问题在于,我们无法在IE11中跨域发布到命名选项卡中

相反,让我们创建一个文件,该文件将使用查询字符串params构建表单

现在只需向该文件发出get请求

首先,使用以下代码创建一个名为postdirect.htm的文件:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <script type="text/javascript" src="HTMLClient/Scripts/jquery-2.2.4.min.js"></script>
    <script type="text/javascript">

        //This adapter file allows POSTing to any url via a GET
        //Main advantage of this method is that it is IE11 compatible (posting to new named tab is no longer possible in IE11 w/o adjusting the security policy)

        //Must pass a param called url

        $(document).ready(function () {

            //get all the params from the query string
            var urlParams;
            (window.onpopstate = function () {
                var match,
                    pl = /\+/g,  // Regex for replacing addition symbol with a space
                    search = /([^&=]+)=?([^&]*)/g,
                    decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
                    query = window.location.search.substring(1);

                urlParams = {};
                while (match = search.exec(query))
                    urlParams[decode(match[1])] = decode(match[2]);
            })();

            var postLaunch = function (url, params) {

                var form = document.createElement("form");
                form.setAttribute("method", "post");
                form.setAttribute("action", url);
                for (var i in params) {
                    if (params.hasOwnProperty(i)
                        && i != 'url' //no need to submit the url param itself
                        ) {
                        var input = document.createElement('input');
                        input.type = 'hidden';
                        input.name = i;
                        input.value = params[i];
                        form.appendChild(input);
                    }
                }
                document.body.appendChild(form);
                form.submit();               
            };

            postLaunch(urlParams['url'], urlParams);
        });
    </script>
</body>
</html>

因此允许问答式问题。试着问一个新问题,你会在底部看到一个特殊的复选框,启用这个功能。看这个-是的!但是,答案应该是非常好的,而且不应该是IE11中新标签中没有任何解决方案的重复。看到这个讨论了吗-
    var params = {
        url: 'http://oris.co.palm-beach.fl.us/or_web1/new_sch.asp',
        search_by: 'Official Book/Page',
        RecSetSize: 100,
        PageSize: 20,
        search_entry: '24799-0613'
    };
    window.open('/postredirect.htm?' + $.param(params), '_blank');