一、示例

< >
    document.write(location.host + \"<br>\");//返回主机名和端口号
    document.write(location.hostname + \"<br>\");//返回主机名
    document.write(location.href + \"<br>\");//返回完整的URL
    document.write(location.pathname + \"<br>\");//返回URL的路径部分
    document.write(location.port + \"<br>\");//返回端口号
    document.write(location.protocol + \"<br>\");//返回协议
    document.write(location.search + \"<br>\");//返回问号开始的查询部分
  /*document.write(location.assign(\"http://www.baidu.com\"));加载新的文档
    document.write(location.reload(false));重新加载当前文档
    参数为false ,如果服务器的文档改变,则会从服务器下载新的文档,如果服务器文档未改变,则从缓存中加载
    参数为true,强制从服务器下载新的文档,跳过缓存
    document.write(location.replace(\"http://www.baidu.com\"))用新的文档替换当前文档
    replace()方法不会创建新的历史记录,而是直接将之前的历史记录替换
    */
</ >

 

收藏 打印