Copied to clipboard

Flag this post as spam?

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


  • David 13 posts 33 karma points
    Jan 18, 2011 @ 12:26
    David
    0

    Adding Javascript to header contents dynamically

    I am creating a site which will tie in to numerous affiliate sites.  Each of these affiliates has different javascript that needs to be added to the header contents of the page.  I would like to just use one template with a contentplaceholder and add the script dynamically.  I've tried adding a textbox multiple on the doctype and then adding an umbraco item within the contentplaceholder but I get a potentially dangerous code error when trying to save and publish.  Am I missing something ... am I going about this the wrong way .... does anyone have any ideas?

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Jan 18, 2011 @ 13:21
    Michael Latouche
    0

    Hi David,

    Maybe you can create a javascript files "pool" somewhere in your site structure and then add a multipicker as document type property, pointing to that pool. Then you only need to create a macro which you can integrate in your contentplaceholder, to get the list of items selected on the document and generate the proper JavaScript includes.

    Hope this helps.

    Cheers,

    Michael.

  • Chris Houston 535 posts 980 karma points MVP admin c-trib
    Jan 18, 2011 @ 23:47
    Chris Houston
    0

    Hi David,

    I have tried to reply to your post 3 times now, and each time our seems to be letting me down and not saving it, so you might end up with three responses, or none!

    I agree with Mike that you should probably do this using a XSLT or .NET macro.

    You might find that the ability to add XSLT files anywhere on a page is also useful, have a look at the following WIKI page:

    http://our.umbraco.org/wiki/reference/umbracolibrary/registerjavascriptfile

    Cheers,

    Chris

Please Sign in or register to post replies

Write your reply to:

Draft