开发者

javascript call inside a bookmark

开发者 https://www.devze.com 2023-04-11 20:47 出处:网络
wondering if it is possible to have a javascript call inside a html bookmark like: <a href=\"bookmark\">Go do开发者_运维百科wn</a>

wondering if it is possible to have a javascript call inside a html bookmark like:

<a href="bookmark">Go do开发者_运维百科wn</a>
.
.
.
<a name="down" href="javascript:alert('movedhere')">

so when visitor clicks on "Go down" the alert message appears but also when url="/#bookmark" then again the function is called.


It's neither scalable nor elegant but it would work if you checked the fragment of the current page when the page loads:

<script>
function myCallback()
{
    alert('movedhere');
}
</script>

<a href="#down" onclick="myCallback()">Go down</a>
.
.
.
<a name="down">

<script>
var frag = window.location.hash;
if (frag === '#down')
{
    myCallback();
}
</script>

https://developer.mozilla.org/en/window.location#Properties


No, you can't do that exactly, but you can add the script to the actual link instead.

<a href="#down" onclick="alert('movedhere')">Go down</a>
.
.
.
<a name="down">
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号