• Resolved eddrimmer

    (@eddrimmer)


    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/

Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter eddrimmer

    (@eddrimmer)

    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

    (@basszje)

    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

    (@eddrimmer)

    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

    (@basszje)

    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

    (@eddrimmer)

    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

    (@basszje)

    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

    (@eddrimmer)

    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

    (@basszje)

    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

    (@eddrimmer)

    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

    (@eddrimmer)

    Marking as resolved

    Plugin Author Bas Schuiling

    (@basszje)

    I forgot about that setting. Nice to know this works.

    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

    (@basszje)

    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.