获得网站二级域名的方法? [英] a way to get the secondlevel domain of a website?

查看:244
本文介绍了获得网站二级域名的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你知道一种通过类似于 document.location.hostname 的网站获取网站的二级域名的方法吗?

Do you know of a way to get the secondlevel domain of a website via javascript similar to document.location.hostname?

我想创建一个mailto bookmarklet,它从字符串info @和第二级域生成一个电子邮件地址。 document.location.hostname的问题是www。字首。

I want to create a mailto bookmarklet that generates an email address from the string "info@" and the secondlevel domain. the issue with document.location.hostname is the "www." prefix.

推荐答案

快速肮脏...

var domain = location.hostname.split('.').slice(1).join('.');

但这只会剥夺第一部分。如果您有多个级别的服务器名称,那将不会起作用。你应该可以弄清楚。

But that's only going to strip off the first part. If you've got more than one level of server name, that's not going to work. By you should be able to figure it out.

这篇关于获得网站二级域名的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆