<script type="text/javascript">
$(document).ready(function() {
$("body").css("display", "none");
$("body").fadeIn("slow");
$("a.link").click(function(event){
event.preventDefault();
linkLocation = this.href;
$("body").fadeOut("slow", redirectPage);
});
function redirectPage() {
window.location = linkLocation;
}
});
</script>
It does not work “fadeOut” when using “onclick”. As can be implemented without using the “href”?
<a class="link" onclick="window.location='index.php'">index.php</a>
You script works with this:
It fades out the “body” and afterwards it redirects to google.
It also works without the href:
In this case it will just “refresh” the current page.
If you don’t want to store the link within the href-attribute, you can do this:
This is valid HTML and you can, instead of the href-attribute read the new one:
You don’t have to set another “onclick” handler within the link. Because this one will fire first, before the jQuery event handler gets it’s work done.