如何使用javascript历史记录推送状态删除所有获取变量?
它应该适用于以下情况:
http://example.com/slug1/slug2/index.php?myvar=1&myvar2=4
http://example.com/index.php?myvar=1&myvar2=4
http://example.com/slug1/slug2/?myvar=1&myvar2=4
http://example.com/slug2/?myvar=1&myvar2=4
之后应该是这样的:
http://example.com/slug1/slug2/index.php
http://example.com/index.php
http://example.com/slug1/slug2/
http://example.com/slug2/
也许像这样的函数:
function removeGetVariablesFromUrl() {
// Do stuff
}
它不应该返回带有更改的地址,它应该更改地址字段中的实际URL而不重新加载页面。
答案 0 :(得分:1)
以下是在javascript中执行此操作的动态方法:
[Mon Apr 11 21:36:15 2016] [notice] child pid 8781 exit signal Floating point exception (8)
[Mon Apr 11 21:36:15 2016] [notice] child pid 8783 exit signal Floating point exception (8)
[Mon Apr 11 21:36:15 2016] [notice] child pid 8784 exit signal Floating point exception (8)
[Mon Apr 11 21:36:15 2016] [notice] child pid 8787 exit signal Floating point exception (8)
[Mon Apr 11 21:36:15 2016] [notice] child pid 8788 exit signal Floating point exception (8)
[Mon Apr 11 21:36:15 2016] [notice] child pid 8789 exit signal Floating point exception (8)
[Mon Apr 11 21:36:15 2016] [notice] child pid 8793 exit signal Floating point exception (8)
[Mon Apr 11 21:36:15 2016] [notice] child pid 8794 exit signal Floating point exception (8)
这会将您带到当前网址并删除任何内容,包括'?'符号(表示$ _GET变量)
答案 1 :(得分:0)
这很简单:
function removeGetVariablesFromUrl(my_url) {
my_url = "An url without get variables";
history.pushState({}, 'The title', my_url);
}