shreya shreya - 5 months ago 10x
Javascript Question

How do i refresh the contents of a page and return to the same page using javascript

I have the following code

<input type="reset" value="Reset" data-theme="b"
data-inline="true" onclick="refresh()" />
<script type="text/javascript">
function refresh() {

Here onclick of reset button..refresh function is called which refreshes the contents...
The issue is that..I am using several tabs in a when I refresh the contents in a particular tab,upon refreshing its going to the initial tab declared (i.i tab2)

$(function() {
$(function() {
$('#tabs-1 .ui-tabs-nav a[href="#tabs-2"], #tabs-2').addClass('status1');

So how can i refresh the contents and return back to the tab in which i was working and not to the initial tab...


The easiest way is to:-

1. Get the current tab number in the below code:

function refresh()
  // Write your code here to get current tab
  // Assume tab is #tab2
  //Url is: http:
  // location.reload(true);
  var current_url = ""; //Get the current page here
  window.location = current_url + "#tab2";

2: Write the code to activate a tab from the url

$(function() {
    if(window.location.hash) {
          var activeTab = window.location.hash;
          // Write the code to active the tab active here
          $('#myTab a[href="' + activeTab + '"]').tab('show');
      } else {
          // No hash found
          // Write the code to active the the default tabe
          $('#myTab a[href="#tab1"]').tab('show');