📜  HTML | DOM 位置主机名属性

📅  最后修改于: 2021-11-08 06:14:00             🧑  作者: Mango

HTML 中的Location 主机名属性用于返回当前 URL 的主机名。 Location 主机名属性返回一个字符串,其中包含域名或 URL 的 IP 地址。

句法:

  • 它返回主机名属性。
    location.hostname
  • 它用于设置主机名属性。
    location.hostname = hostname

下面的程序说明了 HTML 中的 Location 主机名属性:

例子:



  

    DOM Location hostname Property
    

  

    

GeeksforGeeks

    

DOM Location hostname Property

    

      For returning the hostname of the current       URL, double click the "Return hostname" button:     

         

       

输出:

点击按钮后:

支持的浏览器: Location hostname 属性支持的浏览器如下:

  • 谷歌浏览器
  • IE浏览器
  • 火狐
  • 歌剧
  • 苹果浏览器