Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.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_Html_Hyperlink - Fatal编程技术网

链接到另一页上的javascript链接

链接到另一页上的javascript链接,javascript,html,hyperlink,Javascript,Html,Hyperlink,带有JS链接的目标页面: dest.htm <html> .. <a href="javascript:function(parameters);">JS LINK</a> .. </html> <html> .. <a href="dest.htm">Destination page</a> .. </html> <a href="dest.htm#foo">Destination

带有JS链接的目标页面:
dest.htm

<html>
..
<a href="javascript:function(parameters);">JS LINK</a>
..
</html>
<html>
..
<a href="dest.htm">Destination page</a>
..
</html>
<a href="dest.htm#foo">Destination page</a>
<script>
    if(location.hash === '#foo') {
         yourfunction();
    }
</script>

..
..
来源页面:
origin.htm

<html>
..
<a href="javascript:function(parameters);">JS LINK</a>
..
</html>
<html>
..
<a href="dest.htm">Destination page</a>
..
</html>
<a href="dest.htm#foo">Destination page</a>
<script>
    if(location.hash === '#foo') {
         yourfunction();
    }
</script>

..
..

目前,我正在链接到目标页面。用户必须手动点击JS函数链接。我是否可以链接到目标页面,以便在页面加载时启动相应的功能?

也许dest.html上的
就足够了:)

不直接。但是,您可以使用一个特殊的
查询字符串调用该站点,该字符串可以被目标页面中的javascript检测到

origin.htm

<html>
..
<a href="javascript:function(parameters);">JS LINK</a>
..
</html>
<html>
..
<a href="dest.htm">Destination page</a>
..
</html>
<a href="dest.htm#foo">Destination page</a>
<script>
    if(location.hash === '#foo') {
         yourfunction();
    }
</script>

dest.htm

<html>
..
<a href="javascript:function(parameters);">JS LINK</a>
..
</html>
<html>
..
<a href="dest.htm">Destination page</a>
..
</html>
<a href="dest.htm#foo">Destination page</a>
<script>
    if(location.hash === '#foo') {
         yourfunction();
    }
</script>

如果(location.hash=='#foo'){
yourfunction();
}