Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Darren 2 posts 72 karma points
    Sep 02, 2015 @ 03:30
    Darren
    0

    Adding Content to Umbraco with javascript

    I have been trying to add a content with a script element and with onclick event. Every time i try saving it, it removes the onclick tag and script element. I already tried adding script tag in the tinymce config. Can anyone please shed some light on this issue?

  • Marc Goodson 2149 posts 14377 karma points MVP 9x c-trib
    Sep 02, 2015 @ 08:08
    Marc Goodson
    0

    Hi Darren

    Adding the <script element within a rich text area in Umbraco, may not be the best approach to achieve what you are attemping to do.

    Normally I would add a css class or Id to a html element in the rich text area, and then use javascript in a <script specified in the page template, to target the css class/ Id and bind to the 'click()' event of the element.

    That said you should be able to configure the addition of the onclick attribute to an anchor tag in the tinymce config, if it isn't there already:

    +a[id|style|rel|rev|charset|hreflang|dir|lang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur|onclick|
    ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup]
    

    If it is an image you are trying to add the onclick event to, in earlier versions of Umbraco there was a setting called 'allowedAttributes' for imaging in the umbracoSettings.config, that would also cause onclick attributes to be stripped from images eg:

    <settings>
      <content>
        <imaging>
          <!-- what file extension that should cause umbraco to create thumbnails -->
          <imageFileTypes>jpeg,jpg,gif,bmp,png,tiff,tif</imageFileTypes>
          <!-- what attributes that are allowed in the editor on an img tag -->
          <allowedAttributes>src,alt,border,class,style,align,id,name,onclick,usemap,onmouseover,onmouseout</allowedAttributes>
    

    and you had to update this along with the tinyMCE config

  • Darren 2 posts 72 karma points
    Sep 08, 2015 @ 13:00
    Darren
    0

    Thank you so much Marc on your reply.

    What i am actually trying to do is a migration of a Custom ASP Classic CMS to Umbraco. If i have to update the javascript events, it would take ages as there are a lot of pages.

    I will try your suggestion on adding them on the config files. Will let you know with the results when i am done.

Please Sign in or register to post replies

Write your reply to:

Draft