本文介绍了使用Javascript获取当前域名(不是路径等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我计划为同一网站购买两个域名。根据使用的域名,我计划在页面上提供略有不同的数据。有没有办法让我检测页面加载的实际域名,以便我知道要将内容更改为什么?I plan on buying two domain names for the same site. Depending on which domain is used I plan on providing slightly different data on the page. Is there a way for me to detect the actual domain name that the page is loading from so that I know what to change my content to?我环顾四周像这样的东西,但大多数都没有按照我想要的方式工作。I've looked around for stuff like this but most of it doesn't work the way I want it to.例如使用时document.write(document.location) on JSFiddle 它返回 http://fiddle.jshell.net/_display/ ie实际路径或其他任何东西。i.e. the actual path or whatever that is.推荐答案怎么样:window.location.hostname location 对象实际上有一个属性引用URL的不同部分The location object actually has a number of attributes referring to different parts of the URL 这篇关于使用Javascript获取当前域名(不是路径等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-24 10:45