0

I'm using Jquery/Ajax to load html pages into a div on my website. I get links certain class to open up in the specified div. When doing this the address bar remains www.example.com. Due to the fact that I do have several pages that I will like to be able to share; so when people visit the links it will take them to the website but with the specific page loaded into the div container.

Here's a few lines of my code

$( document ).ready(function() {
     $.ajax({
    method: 'GET',
    url: "pages/promo.html",
    success: function(content)
    {
        $('#contentarea').html (content);
    }
    });
});



$('.menu_nav') .click (function () {
    var href = $(this) .attr('href');
    $('#contentarea').hide() .load(href).slideDown( 'very slow' )
    return false;
}); 
worldofjr
  • 3,868
  • 8
  • 37
  • 49
Trillumonopoly Inc
  • 115
  • 1
  • 1
  • 11

2 Answers2

0

Unless the other pages are on your domain, you cannot do this. If the other pages are, see this StackOverflow question: Updating address bar with new URL without hash or reloading the page.

Here's the deal: since you are loading a new page and you want the URL of the browser to point to that page, you should just give users a link. They know how to use the back button. (You could use the information in the linked answer to to change the URL to something like this: http://www.trillumonopoly.com/other-website.com.)

Community
  • 1
  • 1
Jacob Brazeal
  • 654
  • 9
  • 16
0

You can use the history object.

$('#contentarea').html(content);
history.pushState({url: "pages/promo.html"}, "", "pages/promo.html");

With the use of the state {url: "pages/promo.html"} you can load your page into your div when your users navigate back/forward.

$(window).on("popstate", function(e) {
    if (e.originalEvent.state != null)
    {
        // AJAX load e.originalEvent.state.url
    }
})
gre_gor
  • 6,669
  • 9
  • 47
  • 52
  • where do I put this on every page or the main page that the other pages are being loaded into? Or Do I just replace the top part of my script that I posted with this – Trillumonopoly Inc Feb 02 '16 at 21:15