document.location的用法实例
<html> <head> <title>document.location </title> </head> <body> <b>document.location使用举例 </b ><p> <script type ="text/javascript"> document.write( " 当前位置: " + document.location + " <p> " ); document.write( " 当前位置的url路径: " + document.location.pathname + " <p> " ); document.write( " 当前位置的url协议: " + document.location.protocol + " <p> " ); document.write( " 当前位置的url端口: " + document.location.port + " <p> " ); // 设置新的location //document.location.href= " http://www.baidu.com " ; window.open('http://www.baidu.com'); </script> </body> </html>
运行后,打印结果是:
document.location使用举例
当前位置: http://localhost/yacol/js/document.html
当前位置的url路径: /yacol/js/document.html
当前位置的url协议: http:
当前位置的url端口:
document.location.href= " http://www.baidu.com " ;//转到百度
window.open('http://www.baidu.com');//在新窗口打开百度