0
Welcome Guest! Login
0 items Join Now

Add javascript to a Joomla menu item

  • Add javascript to a Joomla menu item

    Posted 12 years 7 months ago
    • I'd like to add some javascript to a menu item...this would let me save a cookie and get it's value later...like so:

      <a class='portal' href="index.php/portals" onclick="javascript:Cookie.write('disease', 'amblyopia');">Amblyopia</a>

      But how to get the onclick event into the menu item from within Joomla? Doesn't appear that this is allowed.

      Ideas?

      Roger
    • Who?'s Avatar
    • Who?
    • Preeminent Rocketeer
    • Posts: 25562
    • Thanks: 613
    • Joomla freelancer

    Re: Add javascript to a Joomla menu item

    Posted 12 years 7 months ago
    • You will have to use some third party extensions for that. For example, I would use ReReplacer extension 8)
    • Check my services at: Mihha-Vision
  • Re: Add javascript to a Joomla menu item

    Posted 12 years 7 months ago
    • Thanks, Rereplacer is a good temporary solution. My fear is that it would slow down the site, since it searches the whole text of every page, every page load.

      Surprised there's not a menu module out there that does this already.

      Roger
    • Who?'s Avatar
    • Who?
    • Preeminent Rocketeer
    • Posts: 25562
    • Thanks: 613
    • Joomla freelancer

    Re: Add javascript to a Joomla menu item

    Posted 12 years 7 months ago
    • You can try to use one Joomla bug with "External URL" menu type

      Here is how:

      1. create one menu item with External URL menu type
      2. for Link parameter put EXACTLY the following (do not change anything)
      index.php/portals" onclick="javascript&#058;Cookie.write('disease', 'amblyopia');"

      That could work since it uses, as I said, one bug present in Joomla. On the other hand, it could stop working in the future if joomla bug squad decide to fix this bug 8)
    • Check my services at: Mihha-Vision
  • Re: Add javascript to a Joomla menu item

    Posted 12 years 7 months ago
    • Wow, great solution... So...why is it a bug if it's so useful? :)
    • Who?'s Avatar
    • Who?
    • Preeminent Rocketeer
    • Posts: 25562
    • Thanks: 613
    • Joomla freelancer

    Re: Add javascript to a Joomla menu item

    Posted 12 years 7 months ago
    • Is it working for you? It is a bug because in that way you can put almost anything in link parameter and that is just wrong. Better would be to create additional link parameters which could be validated then 8)
    • Check my services at: Mihha-Vision

Time to create page: 0.076 seconds