Solved

Javascript onclick

Posted on 2014-03-05
6
1,771 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
Industry Leaders: 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

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!

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
Suggested Courses

615 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