[HELP] Url stays the same

Status
Not open for further replies.

Kaz

BooYah
Staff member
Nov 16, 2010
3,065
1,033
Basically when i visit a url,
For example if i was on 127.0.0.1 and i navigated to 127.0.0.1/home.php (or something similar) how can i get the url to stay as 127.0.0.1 in the address bar?

I have read up on this and i know it can be done via iFrames, however it can also be done via AJAX (which id prefer)
I have looked about and so far havent found anything which relates to this.

If anyone knows how to do this or knows somewhere which would explain it abit more, could you help me or link me.

Before anybody says its bad practise and restricts parts of the site (eg, if a user was on an interesting page, they wouldnt be able to send the link to their friend as the url is 127.0.0.1 and not 127.0.0.1/interesting_link_here)
I have an idea i want look into further and keeping the url as 127.0.0.1/blahblah could result in a user cheating, meaning if they lost/get it wrong they can simply go back to the previous page, which i dont want them to do)
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,935
3,936
You could use jQuery's load() function:


Also, I wrote an example here:
 

Kaz

BooYah
Staff member
Nov 16, 2010
3,065
1,033
Right, i have been looking over it on jquery.com
Would this work for multiple pages?

For example, if i had 127.0.0.1/1/a (/b /c /d etc....)
and 127.0.0.1/2 (/a /b /c /d etc... )
(/1 will have certain content on and /2 will have something completely different meaning i cannot merge them into 1 file)
although having alot of pages, will it work and keep the url as 127.0.0.1 as im unsure (never touched jquery before, so im not 100% on how it all comes together yet)
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,935
3,936
How are you fetching pages? are they being dynamically created? or are they static HTML pages?

Also, your URLs wouldn't change, however, you could hash them like so:


That way a user could share that page, and JS would read that hash and load it.

For example, you could do something like this:
Code:
$(document).ready(function() {
 
    // this is triggered when the page first loads
 
    if(window.location.hash != '') {
 
        openPage(window.location.hash);
 
    }else{
   
        openPage('home');
 
    }
 
    // this is triggered when a link with the class "load" is clicked
 
    $('body').on('click', '.load', function(e) {
     
        e.preventDefault(); // kills the link
 
        var page = $(this).attr('href');
  
        window.location.hash = page; // set the new page hash
 
        openPage(page);
 
    });
 
    function openPage(page) {
 
        $('#myContent').load(page + '.php');
 
    }
     
});

Then your links would look like this:
Code:
<a class="load" href="home">Home</a>

Note: this is not tested.
 

Kaz

BooYah
Staff member
Nov 16, 2010
3,065
1,033
Currently the pages im loading are static, however like i said im wanting to hide the links from the url so nobody can view the current page link/go back a page as they could cheat that way (unless there is a way to prevent people from using it on my site)
Ill take a look into it further and have a play around, i now have a little more info than what i had previously
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,935
3,936
Currently the pages im loading are static, however like i said im wanting to hide the links from the url so nobody can view the current page link/go back a page as they could cheat that way (unless there is a way to prevent people from using it on my site)
Ill take a look into it further and have a play around, i now have a little more info than what i had previously
You could use PHP sessions so that you know what page they are on, and then only allow them to go to the next page.
 
Status
Not open for further replies.

Users who are viewing this thread

Top