首页IT科技获取当前页面的url(获取当前页面域名的几种方式)

获取当前页面的url(获取当前页面域名的几种方式)

时间2025-06-20 21:43:44分类IT科技浏览4554
导读:获取当前页面域名的几种方式:...

获取当前页面域名的几种方式:

(1)方法一:

<script type="text/javascript"> hname=window.location.host; function disp_alert() {alert(hname);} </script>

当前页面的运行结果为:

www.yuucn.com

(2)方法二:

<script type="text/javascript"> hname=document.domain; function disp_alert() {alert(hname);} </script>

当前页面的运行结果为:

yuucn.com

(3)方法三:

<script type="text/javascript"> hname=window.location.href; function disp_alert() {alert(hname);} </script>

当前页面的运行结果为:

https://www.yuucn.com/a/1594551.html

总结: window.location.host             、document.domain                  、window.location.href三个方式获取的内容是不一样的            ,在选择的时候                   ,根据自己想要的内容      ,使用相应的代码             。

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
购物车的东西如何删除(WooCommerce购物车按钮删除和隐藏几种方法(购物车里怎删掉))