Solved

Javascript onclick

Posted on 2014-03-05
6
1,664 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
  • 3
  • 3
6 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
Comment Utility
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
Comment Utility
Thanks, but I think that code is jquery. Can you show me an example as pure JavaScript.
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
It is and WP comes with jquery so why would you want plain javascript?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:petewinter
Comment Utility
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
Comment Utility
Yep
0
 

Author Closing Comment

by:petewinter
Comment Utility
Many thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Open a div with click on an image 7 38
C3-->D3 Line Chart 4 16
JavaScript error 1 32
MSSQL 2008 with mySQL webservers 7 23
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now