链接到另一页上的javascript链接
带有JS链接的目标页面:链接到另一页上的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
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();
}