Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 有没有办法知道链接来自哪里?_Javascript_Hyperlink - Fatal编程技术网

Javascript 有没有办法知道链接来自哪里?

Javascript 有没有办法知道链接来自哪里?,javascript,hyperlink,Javascript,Hyperlink,我想知道JavaScript中是否有一种明确的方式来判断在某个网页上单击的链接是否会将用户发送到该网站上的另一个网页或将用户发送到某个外部网站 这里有一个小例子来说明我的意思: <a href="another_page.html">A link to another page on website</a> <a href="http://google.com/">A link to an external page from a different webs

我想知道JavaScript中是否有一种明确的方式来判断在某个网页上单击的链接是否会将用户发送到该网站上的另一个网页或将用户发送到某个外部网站

这里有一个小例子来说明我的意思:

<a href="another_page.html">A link to another page on website</a>
<a href="http://google.com/">A link to an external page from a different website</a>

当单击其中一个链接时,是否有明确的方法来判断单击的url是否会指向当前站点或某个外部站点上的另一个页面

我主要想知道,在用户进入页面之前,JavaScript是否有某种方式可以通过单击链接来判断链接是外部链接还是内部链接。

您可以使用

document.location.hostname

我会给你自己域名的位置,然后检查它是自己的域名还是去其他地方,或者检查http

@ncubica我把我原来的问题改写了一点;我想知道点击的链接是否会将用户重定向到外部网站或内部网页,然后再实际转到该网页。这不只是告诉我当前网页的主机是什么,而不是链接将转到何处吗?如果我错了,请纠正我