Copied to clipboard

Flag this post as spam?

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


  • Kasper Gadensgaard 31 posts 52 karma points
    Jul 15, 2012 @ 09:40
    Kasper Gadensgaard
    0

    How to use RegisterJavaScriptFile to register remote script

    Hi,

    I am creating a video player macro based on the VideoJS player (http://videojs.com/).

    For that i need to include a javascript file and a css file, so i use RegisterJavaScriptFile and RegisterStyleSheetFile respectively. 

    The CSS file is included nicely, however the RegisterJavaScriptFile registers the script at a local url even though it is remote.

    That is, when registering the script i use

    <xsl:value-of select="umbraco.library:RegisterJavaScriptFile('videoJS', 'http://vjs.zencdn.net/c/video.js')" />

    however that results in an output of 

    <script type="text/javascript" src="~/http://vjs.zencdn.net/c/video.js?cdv=1"></script>

    which obviously returns a 404.

     

     

  • Brendan Rice 372 posts 608 karma points
    Jul 16, 2012 @ 00:52
    Brendan Rice
    0

    Here is the method you are calling into, I had a look to see what it would be getting prefixed with a tilda (~). It looks like the ClientDependenceLoader needs a relative path, therefore the external file won't work.

    It might be worth requesting that a RegisterExternalJavaScriptFile helper method gets created or better yet you could write one yourself.

    public static void RegisterJavaScriptFile(string key, string url)
    {
        Page currentHandler = HttpContext.Current.CurrentHandler as Page;
        if (currentHandler != null)
        {
            if (ClientDependencyLoader.Instance == null)
            {
                HtmlGenericControl child = new HtmlGenericControl("script") {
                    ID = key
                };
                child.Attributes.Add("type", "text/javascript");
                child.Attributes.Add("src", url);
                if (currentHandler.Header == null)
                {
                    currentHandler.ClientScript.RegisterClientScriptInclude(currentHandler.GetType(), key, url);
                }
                else if (currentHandler.Header.FindControl(key) == null)
                {
                    currentHandler.Header.Controls.Add(child);
                }
            }
            else
            {
                ClientDependencyLoader.Instance.RegisterDependency(url, ClientDependencyType.Javascript);
            }
        }
    }
    
  • Kasper Gadensgaard 31 posts 52 karma points
    Aug 07, 2012 @ 10:00
    Kasper Gadensgaard
    0

    Registering an external script file is supported in the latest version of the Client Dependency Framework as implemented in Umbraco 4.8

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies