0

basically i am checking if i am in the same url as the page
and i want to refresh the page only once,but whenever i try it keep refreshing infinitively

 place='/development/petersburg';
 var pathname=window.location.pathname;
    if((pathname==place)){

     window.location.reload();//reload the page
 }

help!! how can i limit this page to refresh only once if the condition is true?

4
Contributors
5
Replies
9
Views
5 Years
Discussion Span
Last Post by mrcniceguy
2

Hi,
Try this, adding a #hash for first refresh, then, if no #hash in URL, make refresh

place = '/development/petersburg';
var pathname = window.location.pathname;
if((pathname == place)){
  if(window.location.hash == '') window.location = window.location + '#hashrl';    //reload the page
}

After refresh, the URL wil be: /development/petersburg#hashrl

0

seems like its what i need. but the $_GET method is PHP and am working on file.js ..what is the js way of doing this.

place='/development/petersburg';
 var pathname=window.location.pathname;
    if((pathname==place)){
    if($_GET['refresh'] != 'no'){
     window.location.reload();//reload the page
     }
 }
1

Something using the location.hash ?

place='/development/petersburg';
 var pathname=window.location.pathname;
    if((pathname==place)){
    if(location.hash && location.hash != '#no'){
     window.location.reload();//reload the page
     }
 }
0

Thankx guys, its now working..i added the window.location.hash as both of you suggested.

Edited by mrcniceguy

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.