location对象

location对象表示当前页面的URL信息。例如,一个完整的URL:

http://www.example.com:8080/path/index.html?a=1&b=2#TOP

可以用location.href获取。要获得URL各个部分的值,可以这么写:

location.protocol; // 'http'
location.host; // 'www.example.com'
location.port; // '8080'
location.pathname; // '/path/index.html'
location.search; // '?a=1&b=2'
location.hash; // 'TOP'

要加载一个新页面,可以调用location.assign()。如果要重新加载当前页面,调用location.reload()方法非常方便。

location 对象属性:

QQ截图20161012171542.png

location 对象方法:

QQ截图20161012171548.png

继续学习
||
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>location</title> </head> <script type="text/javascript"> var myurl=window.location.href; document.write("当前网址:"+myurl); </script> </head> <body> </body>
提交重置代码
章节
笔记
提问
课件
反馈
捐赠

弹指间学会JavaScript 教程