Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a new tab with a post request?

Using javascript/jquery, I want to open a new tab. I have this code:

window.open("../scripts/map.php", '_blank');

which does it, but I also want to attach a huge json string as a parameter. I don't want to attach it to the url. Is there a way to make a jquery ajax call, and have the returned html string, set in the new tab?

Thanks.

like image 807
omega Avatar asked Aug 27 '14 01:08

omega


People also ask

How do I open a new tab with node js?

open() method is used to open a new browser window or a new tab depending on the browser setting and the parameter values. Approach: To open a new tab, we have to use _blank in the second parameter of the window. open() method.

How do I open a new tab with contents?

Open a new tab . Or, use a keyboard shortcut: Windows & Linux: Ctrl + t. Mac: ⌘ + t.

How do I get a new tab to open automatically in HTML?

The short answer is: just add a target="_blank" attribute to your links (anchor tags). Now when your visitors click that link, it will open in a new window or tab (depending on which web browser they are using and how they configured that browser).

Can you make the link open in a new tab in JavaScript?

You need to use the _blank value in the target attribute to open the linked URL in a new tab or window. If you want to open URL with JavaScript, the open() method of Window interface is the best option. The JavaScript window. open() method opens a new browser window.


1 Answers

You could define a (possibly hidden) form element, give it the action of the url you want to post to, the method "post", and a target of "_blank", set the json to one of its input fields, the submit the form with jquery using $(form).submit (). You can even use jquery to create and remove the form at runtime.

The target attribute for forms works the same as for hyperlinks.

like image 78
Robert Lee Avatar answered Oct 09 '22 00:10

Robert Lee