url更改没有锚标记并使用ajax刷新

时间:2013-06-25 07:43:21

标签: php jquery ajax url

根据我的客户需要,重定向没有锚标记和刷新页面的页面,  并根据页面外观更改URL。我对此一无所知。 我可以使用ajax来处理页面内容。但我不知道URL更改选项没有 页面刷新或重定向。我怎么能用ajax j-query做到这一点。任何人都会指导我解决这个问题。谢谢提前

示例网址

www.samplesite.com/contact.php - >没有锚标签。和页面刷新这个网址需要在PHP上工作。

3 个答案:

答案 0 :(得分:1)

我认为您正在寻找有关新HTML5历史记录API(pushstate)的信息,此链接有详细的教程。

http://diveintohtml5.info/history.html

答案 1 :(得分:0)

您可以使用以下javascript函数

window.location.assign('http://www.samplesite.com/contact.php'); // keeps the current page in browser history

window.location.replace('http://www.samplesite.com/contact.php'); // replaces the current page in browser history

window.location = 'http://www.samplesite.com/contact.php'; // the same as assign() and is backward compatible even with the oldest browsers

jsfiddle

答案 2 :(得分:0)

您可以使用以下功能执行此操作。

if(pageurl!=window.location){
  window.history.pushState({path:pageurl},'',pageurl);
}