location

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

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

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

    location.protocol; // 'http'

    location.host; // 'www.example.com'

    location.port; // '8080'

    location.pathname; // 'pathindex.html'

    location.search; // '?a=1&b=2'

    location.hash; // 'TOP'

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

    'use strict';



    if (confirm('重新加载当前页' + location.href + '?')) {

    location.reload();

    } else {

    location.assign('discuss'); / 设置一个新的URL地址

    }