7

While writing a post on menu items without an actual link, I stumbled upon a strange behavior in Joomla 3.3.3:

I wanted to point out that an <a> tag linking to "#" might cause the page to scroll to the top when clicked, and that it might be better to use javascript:void(); in the link field for the External URL menu item. (This article explains why.)

I used to do this myself, but now I discovered that in Joomla 3.3.3, it refuses to save if the link field contains javascript:void();. Take a look at this screenshot (before and after hitting the "Save" button):

Before and after Save

I just tested it on an older Joomla version (3.0.3), and I could still use javascript:void(); in the link field.

Is this a bug in newer versions of Joomla, or was it decided that linking to javascript is not allowed anymore, somewhere between J3.0.3 and J.3.3.3?

6

It was actually a bug that it worked (or to be more specific a security issue). The current behaviour is correct.

References:

Menu item type of External URL can not be saved with javascript:void()

How to let menu item execute Javascript in Joomla 3.2?

  • OK, that explains it. – johanpw Sep 3 '14 at 19:22
3

As an addition to Valentin's answer, this is how to add javascript code to a menu item:

  • Create a custom link menu item
  • Add # in the link field
  • Handle the click event by adding javascript elsewhere on the page (e.g. in the footer).

Example:

jQuery(document).ready(function($){   
  $(".menuitemclass").click(function () {
    //your javascript function;     
  });
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.