Solved

Javascript onclick

Posted on 2014-03-05
6
1,733 Views
Last Modified: 2014-03-05
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?
0
Comment
Question by:petewinter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39906849
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.
})
0
 

Author Comment

by:petewinter
ID: 39907061
Thanks, but I think that code is jquery. Can you show me an example as pure JavaScript.
0
 
LVL 58

Expert Comment

by:Gary
ID: 39907069
It is and WP comes with jquery so why would you want plain javascript?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:petewinter
ID: 39907274
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

0
 
LVL 58

Expert Comment

by:Gary
ID: 39907334
Yep
0
 

Author Closing Comment

by:petewinter
ID: 39907762
Many thanks
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question