JavaScript Location object

 

test code

<script type="text/javascript">

//Set or return the URL (anchor) starting with a pound sign (#).
document.write(location.hash);	
document.write("<br>");	

//Set or return the hostname and port number of the current URL.
document.write(location.host);	
document.write("<br>");	
	
//Set or return the hostname of the current URL.
document.write(location.hostname);	
document.write("<br>");	
	
// Set or return the full URL.
document.write(location.href);	
document.write("<br>");	

//Set or return the path portion of the current URL.
document.write(location.pathname);	
document.write("<br>");	

//Set or return the port number of the current URL.
document.write(location.port);	
document.write("<br>");	

//Set or return the protocol of the current URL.
document.write(location.protocol);	
document.write("<br>");	

//Set or return the URL (query part) starting with a question mark (?).
document.write(location.search);	
document.write("<br>");	


</script>

 

access path

http://127.0.0.1:8080/samltest/index/test.jsp?name=hello#a/b

 

output result

#a/b
127.0.0.1:8080
127.0.0.1
http://127.0.0.1:8080/samltest/index/test.jsp?name=hello#a/b
/samltest/index/test.jsp
8080
http:
?name=hello

 

 

 

 

 

Guess you like

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