JavaScript onClick Navigation Issues within Google Chrome are Solved

DevMicrosoftTechTipTutorial

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!

Mar 8 2012 11:47 AM