Solved

Javascript onclick

Posted on 2014-03-05
6
1,758 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

Technology Partners: 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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
The viewer will learn how to dynamically set the form action using jQuery.

734 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