JavaScript onClick Navigation Issues within Google Chrome are Solved
●
Permalink
●
suggest edit
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:
1
<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:
1
<div onClick="location.href='/admin';"><!-- Something here --></div>
This simple change will allow Google Chrome to properly navigate to the page.
Hope that helps!