1

im using this code javascript with localStorage (something like session in php)

<script>
$(function(){
        var a = localStorage.getItem('login');
        if(a=="" || a==null){window.location.href = "dash-home.html";}
        else{window.location.href = "dash-chat.html";}
    }); 
</script>

but when location in dash-home.html, that page always refresh page (F5 repetitive)

1 Answers1

0

I think you understand that AJAX / PHP is the best solution.

But if you cannot use AJAX, you can use the .load() jQuery method to simulate AJAX. .load() will load the contents of another file into your document WHEN and WHERE you want.

Example:

if (condition == true){
    $('targetDIV').load('desired_page.html');
}

http://api.jquery.com/load/


More information about AJAX:

https://stackoverflow.com/a/17974843


For your example:

<script>
    $(function(){
        var a = localStorage.getItem('login');
        if(a=="" || a==null){$('#targetDIV').load("dash-home.html");}
        else{$('#targetDIV').load("dash-chat.html");}
    }); 
</script>

<body>
    <div id="targetDIV"> This is where the other pages will appear </div>
Community
  • 1
  • 1
cssyphus
  • 37,875
  • 18
  • 96
  • 111