Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Post Parameters in Window.open / Window.location.href (Alternative)

In some cases we have a requirement, to POST data i.e. you’re accessing the URL can’t see the Parameters passed, as some information might be sensitive so we can’t pass POST parameters in URL, but there is an alternative way to post parameters.

Let’s see the Example –
The below method is an alternative to Window.open or Window.location.href, if you want to POST the parameters.

JavaScript Method:-

varopenPost = function (url, params) {
    varformElement = document.createElement("form");
    formElement.setAttribute("method", "post");
    formElement.setAttribute("action", url);
    formElement.setAttribute("target", "_parent");

    for(param in params) {
        varhiddenField = document.createElement("input");
        hiddenField.setAttribute("name", param);
        hiddenField.setAttribute("value", params[param]);
        formElement.appendChild(hiddenField);
    }

    document.body.appendChild(formElement);
    formElement.submit();
}

Calling Method to Redirect -
// CALLING THE OPENPOST METHOD TO REDIRECT
varparams = [];                            
params["token"] = “xyz112121212xysy”;
                               
openPost('/your/redirectURL', params);

//END OPEN POST METHOD

Share the post

Post Parameters in Window.open / Window.location.href (Alternative)

×

Subscribe to Angular 2 Javascript Asp.net C# Sql Server Knockoutjs Angularjs Kendo Ui Html 5 Web Api Wpf Wcf Etc.

Get updates delivered right to your inbox!

Thank you for your subscription

×