Search code examples
jquery-mobilejquery-mobile-navbar

How do I open the previous active tab when returning from a new html page


How do I return back to the previous active tab if I am moving back from another html page?

I am having 5 tabs and within content of each tab there are links to another set of html pages. For example I am having a page called 'school.html' and it has 5 tabs. In tab 2 content (it shows individual student details) I am having a link to "Add new student" to a new page named addNewStudent.html.
After adding a new student in addNewStudent.html, I need to automatically comeback to original page with tabs (window.location = 'school.html'). So how to make tab 2 active showing the tab 2 content (student details).


Solution

  • This can be done in two ways depends upon your usage..

    1)if you use browser back in addNewStudent.html to go to school.html.Better to use cookie concept. For ex: when going to addNewStudent.html from school.html setcookie("tabchange","tab2") when coming back from addNewStudent.html to school.html(onload of school.html check whether the cookie exist or not,if exists depends upon cookie enable your tab);

    2) if you use any button or link in addNewStudent.html to go to school.html.Better to use queryparams. for ex: pass tabchange queryparam for school.html to addNewStudent.html?tabchange=tab1 get that queryparam from addNewStudent.html and assign to link or button your as href="/school.html?tabchange=tab1" after clicking that button onload of school.html get the queryparam and enable the tab..