我试图删除文档准备浏览器url中的“?”后的所有内容。
以下是我正在尝试的:
jQuery(document).ready(function($) {
var url = window.location.href;
url = url.split('?')[0];
});
我可以这样做,并看到下面的工作:
jQuery(document).ready(function($) {
var url = window.location.href;
alert(url.split('?')[0]);
});
一个简单的方法做到这一点,工作在任何页面,需要HTML 5
// get the string following the ?
var query = window.location.search.substring(1)
// is there anything there ?
if(query.length) {
// are the new history methods available ?
if(window.history != undefined && window.history.pushState != undefined) {
// if pushstate exists, add a new state to the history, this changes the url without reloading the page
window.history.pushState({}, document.title, window.location.pathname);
}
}
一个简单的方法做到这一点,工作在任何页面,需要HTML 5
// get the string following the ?
var query = window.location.search.substring(1)
// is there anything there ?
if(query.length) {
// are the new history methods available ?
if(window.history != undefined && window.history.pushState != undefined) {
// if pushstate exists, add a new state to the history, this changes the url without reloading the page
window.history.pushState({}, document.title, window.location.pathname);
}
}