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!

If you want to view or submit comments you must accept the cookie consent.