Title: onClick (javascript) How to?
Last modified: August 31, 2016

---

# onClick (javascript) How to?

 *  Resolved [eddrimmer](https://wordpress.org/support/users/eddrimmer/)
 * (@eddrimmer)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/onclick-javascript-how-to/)
 * Hello,
 * Congrats on making a great plugin – looking forward to using this on my site…
 * I need to be able to use javascript ‘onClick’ function on a button URL, which
   I see is now supported but I’m having trouble in working out the correct syntax
   to use in the URL field of the button.
 * I’d like the button to open a URL in a new window, normal HTML would be for example:`
   <a href="http://www.google.com"></a>`
 * How would I do this?
 * Thanks in advance
    Edd
 * [https://wordpress.org/plugins/maxbuttons/](https://wordpress.org/plugins/maxbuttons/)

Viewing 13 replies - 1 through 13 (of 13 total)

 *  Thread Starter [eddrimmer](https://wordpress.org/support/users/eddrimmer/)
 * (@eddrimmer)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/onclick-javascript-how-to/#post-6915348)
 * The HTML I put in as the example didn’t appear, let me try again using the code
   thing:
 * `<a href="http://www.google.com" target="_blank" onclick="window.open(this.href,
   this.target,'height=800, width=700');return false;"></a>`
 *  Plugin Author [Bas Schuiling](https://wordpress.org/support/users/basszje/)
 * (@basszje)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/onclick-javascript-how-to/#post-6915402)
 * Hi Ed,
 * I’m not sure why you would need Javascript for that. If you check the ‘open in
   new window’ checkbox, the URL opens in another window/tab. Why would you want
   to use the code in your example?
 *  Thread Starter [eddrimmer](https://wordpress.org/support/users/eddrimmer/)
 * (@eddrimmer)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/onclick-javascript-how-to/#post-6915422)
 * Hi Bas,
 * Thanks for replying 🙂 Well, the reason is that I want to specify the height 
   + width of the new window and I cannot see any way to do this in any of the settings?
 * So rather than request a feature from you, wanted to use something which you 
   already had implemented! But just wanted to know how to use it.
 * Thanks
    Edd
 *  Plugin Author [Bas Schuiling](https://wordpress.org/support/users/basszje/)
 * (@basszje)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/onclick-javascript-how-to/#post-6915486)
 * You might be better off by using some custom javascript in your theme, but I 
   found a way to do it like this:
 * `javascript:void window.open('http://www.google.com', '_blank', 'width=1024,height
   =768,status=0,resizable=0');`
 *  Thread Starter [eddrimmer](https://wordpress.org/support/users/eddrimmer/)
 * (@eddrimmer)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/onclick-javascript-how-to/#post-6915488)
 * Hi Bas,
 * Thanks again – what exactly would go in the URL field here? I just tried this,
   but it doesn’t work – it opens a new window with `javascript:void window.open('
   http//www.google.com', '_blank', 'width=1024,height=768,status=0,resizable=0')`
   in the address bar?
 * Regards
 *  Plugin Author [Bas Schuiling](https://wordpress.org/support/users/basszje/)
 * (@basszje)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/onclick-javascript-how-to/#post-6915501)
 * In my firefox this opens google ( the URL there ) but it might be that other 
   browser have another way of opening it. If it doesn’t work on other browser you’ll
   need some custom javascript to do it. By the way since the ages of tabbed browsers
   a lot of browser have less support for controlling how windows are being openened.
 *  Thread Starter [eddrimmer](https://wordpress.org/support/users/eddrimmer/)
 * (@eddrimmer)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/onclick-javascript-how-to/#post-6915575)
 * Hi Bas,
 * That’s strange, I put `javascript:void window.open('http://www.google.com', '
   _blank', 'width=1024,height=768,status=0,resizable=0');` in and tried FireFox
   but it opens a blank tab ?
 * I realise the issue regarding tabbed browsers – this is why I’m using javascript
   to open it 🙂
 * Any ideas?
 *  Plugin Author [Bas Schuiling](https://wordpress.org/support/users/basszje/)
 * (@basszje)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/onclick-javascript-how-to/#post-6915577)
 * I tried exactly that and here it works (maybe the linux version is different 
   who knows ) . But if other browsers don’t want to work with this, the only other
   option is adding some custom javascript to your site somewhere and call that.
 *  Thread Starter [eddrimmer](https://wordpress.org/support/users/eddrimmer/)
 * (@eddrimmer)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/onclick-javascript-how-to/#post-6915579)
 * **Never mind!** I have done it!
 * I needed to untick ‘Open in new window’ and it’s all working now.
 * Thanks for your assistance here
    Edd
 *  Thread Starter [eddrimmer](https://wordpress.org/support/users/eddrimmer/)
 * (@eddrimmer)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/onclick-javascript-how-to/#post-6915580)
 * Marking as resolved
 *  Plugin Author [Bas Schuiling](https://wordpress.org/support/users/basszje/)
 * (@basszje)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/onclick-javascript-how-to/#post-6915581)
 * I forgot about that setting. Nice to know this works.
 *  [astrowilliams](https://wordpress.org/support/users/astrowilliams/)
 * (@astrowilliams)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/onclick-javascript-how-to/#post-6915643)
 * I have several functions in a file called functions.js and I would like to execute
   them from MaxButtons. Does the free or upgraded version support this? I have 
   a snippet of the code below I would like to call.
 * function popup() {
    alert(“Hello World”) }
 * // ***************************************************************************************
 * function BetweenDates() {
    var date1 = document.DateDiff.StartDate.value var 
   date2 = document.DateDiff.StopDate.value var IncludeLastDay = document.DateDiff.
   IncludeLastDay.checked date1 = date1.split(“-“); date2 = date2.split(“-“); var
   sDate = new Date(date1[0]+”/”+date1[1]+”/”+date1[2]); var eDate = new Date(date2[
   0]+”/”+date2[1]+”/”+date2[2]); var daysApart = Math.abs(Math.round((sDate-eDate)/
   86400000)); if (IncludeLastDay == true) daysApart = daysApart + 1 var weeksApart
   = daysApart / 7 var LeftoverDays = daysApart % 7 document.DateDiff.TotalDays.
   value = daysApart document.DateDiff.TotalWeeks.value = Math.floor(weeksApart)
   document.DateDiff.LeftoverDays.value = LeftoverDays }
 *  Plugin Author [Bas Schuiling](https://wordpress.org/support/users/basszje/)
 * (@basszje)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/onclick-javascript-how-to/#post-6915654)
 * Please open a new support topic next time. We don’t watch the resolved ones that
   much.
 * To answer, in the same way. Try to add javascript:void popup() to the URL field.

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘onClick (javascript) How to?’ is closed to new replies.

 * ![](https://ps.w.org/maxbuttons/assets/icon-128x128.png?rev=1378636)
 * [MaxButtons - Create buttons](https://wordpress.org/plugins/maxbuttons/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/maxbuttons/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/maxbuttons/)
 * [Active Topics](https://wordpress.org/support/plugin/maxbuttons/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/maxbuttons/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/maxbuttons/reviews/)

 * 13 replies
 * 3 participants
 * Last reply from: [Bas Schuiling](https://wordpress.org/support/users/basszje/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/onclick-javascript-how-to/#post-6915654)
 * Status: resolved