如果您只知道域,如何创建 link

How to create a link if you only know the domain

我想创建一个 link,使用指向我只知道其域的 url 的锚标记。

例如,如果我在浏览器的地址栏中输入 "twitter.com",它会将我带到 https://twitter.com. I want to something similar to this with an anchor tag. I want to have something like and be it a link to https://twitter.com

如果我尝试上面的示例,它会将我带到 mydomain.com/twitter.com,这不是我想要的。

有什么方法可以做到这一点吗?

问题说明:

现在,我有一个域,我想 link 使用锚标记,所以我就这么做了。当我单击 link 时,它不会将我带到网站 "exampledomain.com",而是将我带到 "mydomain.com/exampledomain.com"。我想让 link 带我去 exmpledomain.com。我该怎么做?

您正在使用任何类型的框架吗? 这可能是框架使用 base-url 或某种类型的问题,这就是为什么他将您发送到 mydomain.com/twitter.com,而不是简单地 twitter.com

您可能需要在域名前添加http://https

<a href="http://twitter.com/">twitter</a>

如果您想了解有关 a 标签的更多信息,请查看 Anchor Element page on w3school. 您可以进一步了解 href 属性如何工作:

HTML href Attribute

Value     Description
URL       The URL of the link.

            Possible values:
                 - An absolute URL - points to another web site (like href="http://www.example.com/default.htm")
                 - A relative URL - points to a file within a web site (like href="default.htm")
                 - Link to an element with a specified id within the page (like href="#top")
                 - Other protocols (like https://, ftp://, mailto:, file:, etc..)
                 - A script (like href="javascript:alert('Hello');")

您不能 link 在不添加协议的情况下访问站点,因为 url 可以有任意数量的协议。

Event if link 可以在没有协议值的情况下工作。例如,在下面的布局中:

<a href="//twitter.com">Go twitter</a>

Link 会将您当前的页面 protocol://address 替换为 protocol://twitter.com

因此,如果您的当前页面使用 http 获取,您将被指向 http://twitter.com