2

What I am trying to do is to fadeout div and then reload page, after page reload fadeIn div and stop reloading page. The problem here after fadeOut dive reloading does not stop so fadeOut does not work ?

Code:update

$(document).ready(function () {
    $("#myDiv").fadeOut('slow', function () {
        location.reload(true); 
        $("#myDiv").fadeIn(4500);
    });
});
Saif
  • 2,611
  • 3
  • 17
  • 37

1 Answers1

1

the problem here if i add hash to end of url it will not work properly because url has id = number like this localhost:49208/CMMS/UserView.aspx?id=8

Try setting localStorage first .fadeOut() call , if localStorage has unique item set fade out #myDiv using $.holdReady(), then fade in #myDiv . See also Global Variable usage on page reload

$.holdReady(true);
  if (localStorage.getItem("reload") === "#") {
    $("#myDiv").fadeOut();
  }
$.holdReady(false);
$(document).ready(function () {
    if (localStorage.getItem("reload") === null) {
      $("#myDiv").fadeOut('slow', function () {
        localStorage.setItem("reload", "#");          
        window.location.href = window.location.href            
      });
    } else {
        $("#myDiv").fadeIn(4500);
    }
});
Community
  • 1
  • 1
guest271314
  • 1
  • 15
  • 104
  • 177
  • the problem here if i add hash to end of url it will not work properly because url has `id = number` like this `localhost:49208/CMMS/UserView.aspx?id=8` – Saif Dec 01 '15 at 02:37
  • Try substituting `history` or `localStorage` for query string or hash ; using same process including `$.holdReady()` to check for variables in `window` before `.ready()` handler called ; see link at updated post – guest271314 Dec 01 '15 at 02:37
  • @Smart See updated post ; substituted `localStorage` for setting unique query string or hash at `location.href` – guest271314 Dec 01 '15 at 02:44