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
https://forums.phpfreaks.com/topic/292569-windowhistorypushstate/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.