【问题标题】:Open link in Internet Explorer with POST data using javascript/jquery使用 javascript/jquery 在 Internet Explorer 中使用 POST 数据打开链接
【发布时间】:2019-07-24 11:43:53
【问题描述】:

我正在尝试使用 JS 通过来自任何其他浏览器的 POST 请求在 Internet Explorer 中启动 URL(即从 firefox/chrome/safari 打开 IE)

我的网站在谷歌浏览器中运行。在我的一种方法中,我向客户端的 API 发布了一个请求,它向我返回了一个指向另一个网站的 URL。客户端要求我通过 POST 请求在 Internet Explorer 中自动启动此 URL。现在我知道如何通过发布请求启动 URL,但它会在谷歌浏览器的新窗口中启动 URL。我的问题是如何在 Internet Explorer 中通过 POST 启动此 URL?

我正在使用以下代码在 chrome 的新窗口中通过 post 请求打开此 url。

function OpenWindowWithPost(url, windowoption, name, params) {
    var form = document.createElement("form");
    form.setAttribute("method", "post");
    form.setAttribute("action", url);
    form.setAttribute("target", name);

    for (var i in params) {
        if (params.hasOwnProperty(i)) {
            var input = document.createElement('input');
            input.type = 'hidden';
            input.name = i;
            input.value = params[i];
            form.appendChild(input);
        }
    }

    document.body.appendChild(form);

    window.open("post.htm", name, windowoption);

    form.submit();

    document.body.removeChild(form);
}
OpenWindowWithPost(onlyUrl,
   "width=730,height=345,left=100,top=100,resizable=yes,scrollbars=yes",
   "NewFile", paramsAsObject);

我还尝试通过协议处理程序启动 IE。 (按照这篇文章获取协议处理程序解决方案) Open Internet Explorer from Chrome using a protocol handler (ie:url)

但它只是忽略了我的参数并仅在 IE 中启动基本 URL,这不是我想要的。

有没有一种方法可以同时做这两件事? 1-在 IE 中打开给定的 URL。 2- 通过 POST 请求打开它。

注意:由于客户的要求,我不能在这里使用 GET/Href。

任何帮助将不胜感激。

【问题讨论】:

  • 我认为这是不可能的。你只能在同一个浏览器上这样做

标签: javascript jquery internet-explorer redirect post


【解决方案1】:

使用来自不同浏览器的 javascript/jquery 在 Internet Explorer 中使用 POST 数据打开链接

默认情况下,出于安全原因,浏览器无法启动另一个浏览器。如果你能做到,网站上的任何脚本也会这样做。

因此,您只能使用 window.open() 方法打开一个新标签页或窗口(使用相同的浏览器)。

不知道为什么要使用 IE 浏览器显示网页,但这里有一个扩展 IE Tab,在文档概述中,我们可以看到它可以在 Chrome 中使用 IE 显示网页。你可以检查一下。

【讨论】:

  • 经过大量研究,我终于接受了它不能通过 jquery 完成,我现在使用上述功能“OpenWindowWithPost”在新窗口中通过 HTTP POST 启动 URL。它完美地工作。但我想在同一窗口和同一选项卡中通过 HTTP POST 打开 url。能做到吗?
  • 如果要在同窗口同标签页中打开页面,需要更改window.open()方法参数(从window.open("post.htm", name, windowoption);改为window.open("post.htm", "_self");)。更多window.open方法详情请查看this link
猜你喜欢
  • 2016-04-23
  • 1970-01-01
  • 1970-01-01
  • 2014-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-26
相关资源
最近更新 更多