+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Javascript code does not work in Sitefinity

Javascript code does not work in Sitefinity

4 posts, 0 answered
  1. Yinfang
    Yinfang avatar
    9 posts
    Registered:
    07 May 2012
    18 Oct 2012
    Link to this post
    I have some external JS files used by my master page and my user control. However, the jQuery code does not work at all. I tried using
    <sf:JavaScriptEmbedControl runat="server" id="jsLink1" ScriptEmbedPosition="BeforeBodyEndTag"
            url="~/JS/scripts.js">
    </sf:JavaScriptEmbedControl>


    as well as using

    <asp:ScriptManager ID="ScriptManager" runat="server" LoadScriptsBeforeUI="true"  >
        <Scripts>
            <asp:ScriptReference  Path="~/JS/scripts.js" ScriptMode="Debug" />
        </Scripts>
     </asp:ScriptManager>

    as suggested by http://www.sitefinity.com/devnet/forums/developing-with-sitefinity-/problems-getting-jquery-scripts-to-work-if-only-added-to-the-master-page. Neither of them has solved my problem.  All the JS files are successfully "GET" as shown by FireBug.

    E.g. I set a breakpoint at the "jQuery(document).ready(function ($) " line and tried to step in. However the process paused at the  "jQuery(document).ready(function ($) " line,  and after I hit "step in", it  just exitted, leaving the rest of the initialization code untouched.

    Any suggestions ?
  2. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    18 Oct 2012 in reply to Yinfang
    Link to this post
    Hey Yinfang,

    You can find an example Masterpage here https://gist.github.com/3899224 which uses jQuery and it shows several options of including your own Javascript prior and after the jQuery is loaded. By using the sf:resourceFile tags we avoid jQuery conflicts and double loading of jQuery.

    For some background reading, I suggest:
    http://www.sitefinity.com/devnet/forums/general-discussions-/how-do-i-incorporate-jquery-into-a-master-page

    and

    http://www.sitefinity.com/devnet/forums/general-discussions-/trouble-including-jquery/page/2

    Jochem

  3. Yinfang
    Yinfang avatar
    9 posts
    Registered:
    07 May 2012
    18 Oct 2012 in reply to Jochem Bökkers
    Link to this post
    After I changed the order of JS files in between
    <sf:JavaScriptEmbedControl> and </sf:JavaScriptEmbedControl>, the jQuery code works now. It seems that the order of loading JS files does matter, not like "#include" in C++ nor "import" in Java.
  4. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    18 Oct 2012 in reply to Yinfang
    Link to this post
    @YinFang
      Yes, fun...isn't it :/

    Vote: http://www.telerik.com/support/pits.aspx#/public/sitefinity/13002
4 posts, 0 answered