1

I have created a custom page layout. In that custom page layout I have many HTML markup and controls like Dropdowns, hyperlinks (hrefs) etc. Clicking on hyperlink hides or shows a div. The HTML markup and controls shows up fine when I create a page from page layout. The issue I am having is the JavaScript to hide or show div is in external JS file, which I am referencing in the page layout as below:-

<SharePoint:ScriptLink name="~sitecollection/Style Library/Scripts/my.js" runat="server" />

But when I click on “hyperlinks (hrefs)” the script in external js file doesn’t fire. I also tried using

<script src="../../mysite/Style%20Library/Scripts/my.js"></script>

Any idea what’s wrong?

4 Answers 4

1

You can try with following links:

<script type="text/javascript" language="javascript" src="http://SharePoint/sites/SiteName/_catalogs/masterpage/Master%20Page%20Template/test.js"></script>

<SharePoint:ScriptLink id="ScriptExternalJs" runat="server"  Name="~SiteCollection/Style Library/MyCustomStyles/js/TestScript.js" OnDemand="false" LoadAfterUI="true" Localizable="false" ></SharePoint:ScriptLink>
2
  • I tried with "Script" tag and "ScriptLink" as you suggested but none of them work. I placed those in "PlaceHolderAdditionalPageHead" content area.
    – user117048
    Commented Jun 3, 2014 at 19:09
  • Are you getting any error in your console window?
    – Aanchal
    Commented Jun 4, 2014 at 4:04
0

Refer the js file in script tag and Place it just above the Publishing:EditModePanel tag

<!--MS:<Publishing:EditModePanel runat="server" id="editmodestyles">-->
-1

Create a module in sharepoint like "scripts".

Add ur js file under the module and then refer the file in layout.

1
  • Create a module in sharepoint like "scripts". <?xml version="1.0" encoding="utf-8"?> <Elements xmlns="schemas.microsoft.com/sharepoint"> <Module Name="Scripts"> <File Path="Scripts\jquery-1.8.2.min.js" Url="Scripts/jquery-1.8.2.min.js" /> <File Path="Scripts\JSCSOM.js" Url="Scripts/JSCSOM.js" /> </Module> </Elements> Add ur js file under the module and then refer the file in layout. <asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server"> <script type="text/javascript" src="../Scripts/JSCSOM.js"></script> </asp:Content>
    – user28338
    Commented Jun 4, 2014 at 10:33
-2

You need to add

    //<!{CDATA[//]]>

after each of your script links. i.e.

    <script type = "text/javascript" language="javascript" src="/Style%20Library/myjsfile.js">//<!{CDATA[//]]>

Make sure you put your script link into the 'PlaceHolderAdditionalPageHead' block towards the top of the html page layout - just after the close of the edit mode panel is a good spot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.