Javascript onclick

petewinter
petewinter used Ask the Experts™
on
I am integrating some chat software into my wordpress website and it works with the code below:

<a href="https://hosted2.whoson.com/chat/chatstart.htm?domain=www.frontiercloud.co.uk" onclick="javascript:window.open('https://hosted2.whoson.com/chat/chatstart.htm?domain=www.frontiercloud.co.uk','new_win','width=484,height=361');return false;">Chat</a>

Open in new window


However I need to add this javascript on click command to a Wordpress Menu link and wordpress does not give me this option.

Also tried this plugin and it doesn't seem to work for me: http://wordpress.org/plugins/jin-menu

I assume I should be able to just add a class to the menu link in wordpress, then just add some javascript elsewhere in my code that runs the function when the link with that class is clicked? If so can you please advice how I do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Expert of the Year 2014
Top Expert 2014
Commented:
http://sevenspark.com/how-to/how-to-add-a-custom-class-to-a-wordpress-menu-item

Then you can just add an event to the link

jQuery(".myClassName").click(function(e){
e.preventDefault()
// Your code here.
})

Author

Commented:
Thanks, but I think that code is jquery. Can you show me an example as pure JavaScript.
Expert of the Year 2014
Top Expert 2014

Commented:
It is and WP comes with jquery so why would you want plain javascript?
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
So should code be like the below?

jQuery(".chat_pop a”).click(function(e){
e.preventDefault()
window.open('https://hosted2.whoson.com/chat/chatstart.htm?domain=www.frontiercloud.co.uk','new_win','width=484,height=361');
})

Open in new window

Expert of the Year 2014
Top Expert 2014

Commented:
Yep

Author

Commented:
Many thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start Today