js -> Modify address bar URL and method rewrite without jump

 

 

 

		//Original address abc.com/sss.html
		//abc.com/sss.html#dsf
		window.location.hash = "dsf";
		//abc.com/my/awesome/url
		var stateObject = {};
		var title = "Wow Title";
		var newUrl = "/my/awesome/url";
		history.pushState(stateObject,title,newUrl);

 

Listening to the hash value is: # The following value changes

	window.onhashchange = function(){
		alert(window.location.hash);
	};

 

 

** Override the history.pushState method

 

history.pushState = function(){
	alert("sdf");
}

 

** A complete instance of executing the method according to the hash change

if(window.location.hash != ""){
	window.location.hash = "";
}
window.onhashchange = function(){
	if((window.location.hash).indexOf("show") > -1){
		coverShow();
	}else{
		coverHide();
	}
};
$('.top_bar .menu').tap(function(){
	if((window.location.hash).indexOf("show") > -1){
		window.location.hash = "";
	}else{
		window.location.hash = "show";
	}
			
});
function coverShow(){
	
}
function coverHide(){
	
}

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326586308&siteId=291194637