Invalid window.location.href solution in IE6 browser

  • 2020-03-30 04:21:15
  • OfStack

This article illustrates an example of an invalid window.location.href solution in IE6. Share with you for your reference. Specific methods are as follows:

Window.location.href is a jump function in js. Many people will find that window.location.href cannot jump in ie6.

The problem code is as follows:

<a href="javascript:void(0);" onclick="javascript:test();"> Click to jump </a> 
<script> 
test = function(){ 
  window.location.href = "//www.jb51.net"; 

</script>

 
The correct code is as follows:
<a href="javascript:void(0);" onclick="javascript:test();return false;"> Click to jump </a>  
<script> 
test = function(){ 
 window.location.href = "//www.jb51.net"; 

</script>

 
The reason:
Return false causes the browser's event to not continue to bubble out and fire the browser's default event

conclusion
The principle is not that window.location.href is not compatible but that our return false will make it impossible to jump.


Related articles: