Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change address bar for AJAXed links

    Hello all,
    I'm sure this is coming up quite a bit so maybe someone's got the answer...
    How does one change the text of the address bar to reflect a page change implemented with AJAX?

    In other words, I've got a small site where all the pages are AJAXed into through the index page. However, using PHP/Javascript, I've managed to cobble a function that will change the page given the presence of a page variable in the url string:
    Code:
    //HOME PAGE URL
    http://www.mysite.com
    
    //INSIDE PAGE
    http://www.mysite.com/?page=contact
    That all works fine. However, how can I have javascript change that page variable in the address bar when someone clicks on a link that is ajaxing a page in?

    NOTE: using window.location.hash is not an option as I need to pass a variable for PHP reasons. Any non-hash alternatives?

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,294
    Thanks
    10
    Thanked 583 Times in 564 Posts
    using the search param (?), instead of the hash (#) will cause all current browsers to refresh the page, not something i think you want.

    so, in order to use a url, it would have to be a hash.

    this means that you need to create a 'landing page'- a simple html/js page the immediately converts the hash to a search and transfers the url to your php script.

    note that this would be incoming only; bookmarking a dynamic page would use the search, not the hash. make sure your server can find both versions.

    edit:
    one more idea: use ?s and a full-screen iframe to show your content. the hash of your top page can change while the search of the iframe changes
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •