Jump to content

window.history.pushstate


Pavlos1316

Recommended Posts

I have the below code to open contents in a div or modal window and at the same time showing the url that matches the specified page which works as expected, no problems rising:

$(document).ready(function(){

///////LINK in a Div////////

 $('#all').delegate('a.img-lnk, a.txt-lnk', 'click', function(){
  $('#main').empty();
  var page = $(this).attr('id');
  var pageurl = $(this).attr('data-seo');
  $('#main').load("../"+ page + ".php");
  window.history.pushState('','',pageurl);
 });

///////LINK in a Modal Window////////

 $('#all').delegate('a.pop-lnk', 'click', function(){
  var poppage = $(this).attr('id');
  var popurl = $(this).attr('data-seo');
  $('#popup').load("../char-inf/"+ poppage + ".php");
  window.history.pushState('','',"/char-inf/"+ popurl);
 });

 $('body').delegate('.hide-it', 'click', function(){
  $('.hide-it').hide();
  $('#popup').empty();
  window.history.back();
 });

});

Problem:

If I give you a url of a link in my page e.g. www.example.com/test1 and paste it in your browser the test1 page will open normally,

 

BUT after that if you navigate to page test2 then the new url becomes www.example.com/test1/test2.

 

Is there a way to turn the url at its normal state which would be www.example.com/test2?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.