JavaScript onClick Navigation Issues within Google Chrome are Solved

For the longest time, If I needed to use an onclick event for navigation (div or some other page element), I’d use something similar to:

<div onClick="location.href('/admin');"><!-- Something here --></div>

However, Google Chrome interprets the href property as a method or an object initializer. Instead, to get the onclick navigation to work properly in Chrome, set the property to a value using a typical setter such as:

<div onClick="location.href='/admin';"><!-- Something here --></div>

This simple change will allow Google Chrome to properly navigate to the page.

Hope that helps!

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>