-2

I have a problem regarding to jquery and jsp. I used a jquery load() to load the data on the same page but the main problem was when it was loading the url remains same as the home page but i want to change the url to what the data i have clicked. I already used meta refresh tag but it not working on jsp pages so Please help me to complete the task that to paste the url what the page i have been clicked.I used html tags and javasript and jquery which was saved in jsp pages.

4

2 回答 2

1

使用window.history.pushState

window.history.pushState({},'',"http://newurl.com");

并在jQUery .load示例上:

$("#div").load("http://mysite.com/newpage",function(){
 window.history.pushState({},'newpage', "http://mysite.com/newpage");
});

如果您还想更改文档的标题,请使用:

document.getElementsByTagName('title')[0].innerHTML = 'New Page';
window.history.pushState({},'newpage','http://mysite.com/newpage' );
于 2013-10-26T13:02:47.867 回答
1

如果您担心与旧浏览器和更现代(尽管已过时)的 IE 版本的兼容性,那么您别无选择,我知道您只能使用触发整个页面加载的重定向,或者使用井号,您可以通过

document.location.hash

如果您对此不关心,请查看 HTML5 历史 API ( http://diveintohtml5.info/history.html )

这很简单

history.pushState(null, null, 'newURL')

并且不会破坏与浏览器后退和前进按钮的兼容性,前提是您的页面将这些考虑在内。

于 2013-10-26T12:56:28.933 回答