javascript call inside a bookmark
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">
精彩评论