Javascript 更改窗口位置 Jquery
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3669050/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change window location Jquery
提问by user342391
I am using ajax to load my website content and want to update the window location when ajax is successful.
我正在使用 ajax 加载我的网站内容,并希望在 ajax 成功时更新窗口位置。
How can I update the window location to "/newpage"?? I need users to be able to go back and to refresh. Is this possible??
如何将窗口位置更新为“/newpage”??我需要用户能够返回并刷新。这可能吗??
回答by Munzilla
I'm assuming you're using jquery to make the AJAX call so you can do this pretty easily by putting the redirect in the success like so:
我假设您正在使用 jquery 进行 AJAX 调用,因此您可以通过将重定向置于成功中来轻松完成此操作,如下所示:
$.ajax({
url: 'ajax_location.html',
success: function(data) {
//this is the redirect
document.location.href='/newpage/';
}
});
回答by jwueller
You can set the value of document.location.hreffor this purpose. It points to the current URL. jQuery is not required to do this.
您可以document.location.href为此目的设置 的值。它指向当前的 URL。jQuery 不需要这样做。
回答by Rathienth Baskaran
you can use the new push/pop state functions in the history manipulation API.
您可以在历史操作 API 中使用新的推送/弹出状态函数。
回答by guilleva
Assuming you want to change the url to another within the same domain, you can use this:
假设您想将 url 更改为同一域中的另一个,您可以使用以下命令:
history.pushState('data', '', 'http://www.yourcurrentdomain.com/new/path');
回答by overflow
I'm writing common function for change window
我正在为更改窗口编写通用函数
this code can be used parallel in all type of project
此代码可以在所有类型的项目中并行使用
function changewindow(url,userdata){
$.ajax({
type: "POST",
url: url,
data: userdata,
dataType: "html",
success: function(html){
$("#bodycontent").html(html);
},
error: function(html){
alert(html);
}
});
}
回答by Capt Otis
If you want to use the back button, check this out. https://stackoverflow.com/questions/116446/what-is-the-best-back-button-jquery-plugin
如果您想使用后退按钮,请检查一下。https://stackoverflow.com/questions/116446/what-is-the-best-back-button-jquery-plugin
Use document.location.href to change the page location, place it in the function on a successful ajax run.
使用 document.location.href 更改页面位置,将其放置在成功运行 ajax 的函数中。

