Redirect code not working
I have the ff.code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Videos</title>
<link href="normal.css" rel="stylesheet" /><script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type='text/javascript'>
$(document).ready(function(){
$('.videos').click(function(){
//window.demo.logSectionVisit( "Visited Videos Section" );
$(location).attr('href',"google.com");
//alert(0);
//window.location.href = "http://stackoverflow.com";
});
});
</script>
</head>
<body>
<div id="buttons">
<div id="buttonsleft">
<a href="reset.html" class="reset"><div class="buttonlabel">New Session</div></a>
</div>
<div id="buttonsright">
<a href="" class="videos"><div class="buttonlabel">Videos</div></a>
<a href="" class="slideshows"><div class="buttonlabel">Slide Shows</div></a>
<a href="" class="forms"><div class="buttonlabel">Forms</div></a>
<a href="" class="surveys"><div class="buttonlabel">Surveys</div></a>
<a href="" class="websites"><div class="buttonlabel">Web开发者_如何转开发sites</div></a>
<a href="" class="interactive"><div class="buttonlabel">Interactive</div></a>
<a href="" class="admin"><div class="buttonlabel">Admin</div></a>
</div>
</div>
<div id="mainbody">
<div id="links2">
</div>
</div>
</body>
</html>
I wonder why when I click the videos button, it isn't redirecting. any ideas?
Try to uncomment the line:
//window.location.href = "http://stackoverflow.com";
and comment the line:
$(location).attr('href',"google.com");
Additionally to what Andrew suggests, if you need to have the anchor tag, either remove the href attribute from the anchor or add a preventDefault()
to the click handler as:
$('.videos').click(function(e){
// note that if you redirect to google.com only, it a relative redirect...
// so to go to the actual www.google.com site, use the full url
$(location).attr('href',"http://www.google.com");
e.preventDefault();
});
Instead of
<a href="" class="videos"><div class="buttonlabel">Videos</div></a>
try
<div class="buttonlabel videos">Videos</div>
精彩评论