1

I am trying to use JS to launch a URL in internet explorer via POST request from any other browser (i.e. open IE from firefox/chrome/safari)

My website runs in google chrome. In one of my methods, i post a request to client's API and it returns me a URL to another website. The client requires me to auto launch this URL in Internet Explorer via POST request. Now I know how to launch a URL through post request, but it launches the URL in a new window of google chrome. My question here is that how can I launch this URL via POST in Internet Explorer?

I am using the following code to open this url through post request in new window of chrome.

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

I also tried launching IE through protocol handler. (followed this post for protocol handler solution) Open Internet Explorer from Chrome using a protocol handler (ie:url)

but it just ignores my params and launches just the base URL in IE, which is not what i want.

Is there a way i can do both the things at one time? 1- open the given URL in IE. 2- open it via POST request.

Note: I cannot use GET/Href here due to client's requirements.

Any help would be much appreciated.

Qurat
  • 137
  • 1
  • 1
  • 11

1 Answers1

1

Open link in Internet Explorer with POST data using javascript/jquery from different browser

By default, a browser cannot launch another browser using due to security reasons. If you could do it, also any script on the site would do the same.

So, you could only use the window.open() method to open a new tab or window (using the same browser).

Not sure why you want to use IE browser to display the web page, but here is an extension IE Tab, in the document overview, we can see it could display the web pages using IE within Chrome. You could check it.

Zhi Lv
  • 18,845
  • 1
  • 19
  • 30
  • After a lot of research, i finally accepted that it cannot be done through jquery, i have now launched the URL via HTTP POST in a new window using the above mentioned function "OpenWindowWithPost". It works perfectly. but i want to open the url via HTTP POST in same window and same tab. Can it be done? – Qurat Aug 07 '19 at 09:26
  • If you want to open the page in the same window and same tab, you need to change the window.open() Method parameters(from `window.open("post.htm", name, windowoption);` to `window.open("post.htm", "_self");`). More detail information about window.open method, please check [this link](https://www.w3schools.com/jsref/met_win_open.asp). – Zhi Lv Aug 07 '19 at 09:47