Using Within a Link’s href Attribute

April 10th, 2010 - Posted by Steve Marks to Javascript / jQuery, Web Development.

The Javascript function will open a popup window with a specified URL and is normally placed as a link’s ‘onclick’ action:

Open Popup

Sometimes however, if using a CMS for example, the onclick option of a link is not accessible and all you have access to is the ‘href’ attribute. Placing the function as a link’s href as follows will open the new window but will result in the parent window showing ‘[object Window]’:

Open Popup

To avoid this parent page redirection we need to modify our href slightly:

Open Popup

The ‘void’ operator we’ve added evaluates the given expression and then returns undefined preventing it from doing anything once the new window has been executed.

This entry was posted on Saturday, April 10th, 2010 at 11:25 pm by +Steve Marks and is filed under Javascript / jQuery, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.
Comments (0)
Comments are closed.