JS Working with Tabs



Open new tab from one tab

w = window.open('URL','tabname', "other_option_str");

Check if an opened tab is available or open.
w.closed;   //return true for closed
w.focus();  // open selected tab being on other tab


Submit a form in selected TAB using JS

var    formEL =  $("form").clone();  //create form
formEL.attr("action", "URL");  //set submission url 
formEL.attr("method","post");  //submit type get or post


If we want to submit a form in selected tab we set target attributes. 
formEL.attr("target","tabname");  //default value "_self"/ "_blank"
// here target name will have set as tabname if we want to open in specific tab.


we have to attach the form in a body element to submit it.
$('body').append(formEL);

Finally, we submit the form.
formEL.submit();

Then we can remove the form the BODY element if we want to repeat multiple times.
formEL.remove();




Share this

Related Posts

Previous
Next Post »