在ASP中调用HTML以调用其他脚本

时间:2013-12-04 17:39:38

标签: javascript html asp.net sharepoint

我正在使用sharepoint,我在我的文件中嵌入了jquery,google图表,角度库调用。但是,当我需要添加或删除内容时,返回SharePoint设计器并编辑母版页将变得乏味。

这就是我所拥有的:

    <asp:ScriptManager id="ScriptManager" runat="server" EnablePageMethods="false" EnablePartialRendering="true" EnableScriptGlobalization="false" EnableScriptLocalization="true">
        <Scripts>
                <%-- Libraries/Addons  Nov27/13 --%><asp:ScriptReference Path="/Style Library/libs/jquery-1.10.2.min.js"></asp:ScriptReference>
                    <asp:ScriptReference Path="/Style Library/libs/jquery-ui.min.js"></asp:ScriptReference>
                    <asp:ScriptReference Path="https://www.google.com/jsapi"></asp:ScriptReference>
                    <asp:ScriptReference Path="/Style Library/libs/jquery.SPServices-2013.01.min.js"></asp:ScriptReference>
                    <asp:ScriptReference Path="/Style Library/libs/angular.min.js"></asp:ScriptReference>
                    <asp:ScriptReference Path="/Style Library/libs/knockout-3.0.0.js"></asp:ScriptReference>
                    <asp:ScriptReference Path="/Style Library/addons/wpToggle/wpToggle-jQuery.js"></asp:ScriptReference>
                    <asp:ScriptReference Path="/Style Library/addons/spCharts/spjs-charts-v4.js"></asp:ScriptReference>
                    <asp:ScriptReference Path="/Style Library/addons/quickLaunchToggle/jQuery.LISP.quicklaunch.js"></asp:ScriptReference>
        </Scripts> 
    </asp:ScriptManager>

我正在尝试替换它,而是有一个html文件(或任何允许它工作的东西),而是调用该文件。 例如,如果我有一个包含以下内容的html文件:

 <html>
 <head>
 <title>Script Controller File</title>
 <script type="text/javscript" src="/script1.js"></script>
 <script type="text/javscript" src="/script2.js"></script>
 <script type="text/javscript" src="/script3.js"></script>
 <link href="style1.css" type="text/css" rel="stylesheet" />
 <link href="style2.css" type="text/css" rel="stylesheet" />
 <link href="style3.css" type="text/css" rel="stylesheet" />
 </head>
 </html>

我可以在sharepoint中更改此内容:

        <asp:ScriptManager id="ScriptManager" runat="server" EnablePageMethods="false" EnablePartialRendering="true" EnableScriptGlobalization="false" EnableScriptLocalization="true">
            <Scripts>
                        something something call Script Controller File
            </Scripts> 
        </asp:ScriptManager>

这样,我只需要编辑脚本控制器文件,而不必总是担心编辑SharePoint页面以包含我想要的脚本。这有可能吗?

2 个答案:

答案 0 :(得分:0)

看起来像LABjs的完美用途:(http://labjs.com/

包含一个Javascript文件,其中包含传递给LABjs的其他必需脚本。 LAB将加载它们async / sync并将它们添加到页面的头部。

脚本管理器

<Scripts>
        <asp:ScriptReference Path="/Style Library/libs/LAB.min.js"></asp:ScriptReference>
        <asp:ScriptReference Path="/Style Library/libs/scriptLoader.js"></asp:ScriptReference>
</Scripts> 

<强> scriptLoader.js

$LAB
    .script("/Style Library/libs/jquery-1.10.2.min.js").wait()
    .script("/Style Library/libs/jquery-ui.min.js")
    .script("https://www.google.com/jsapi").wait()
    .script("/Style Library/libs/jquery.SPServices-2013.01.min.js")
    .script("/Style Library/libs/angular.min.js").wait()
    .script("/Style Library/libs/knockout-3.0.0.js")
    .script("/Style Library/addons/wpToggle/wpToggle-jQuery.js")
    .script("/Style Library/addons/spCharts/spjs-charts-v4.js")
    .script("/Style Library/addons/quickLaunchToggle/jQuery.LISP.quicklaunch.js").wait();

我不是100%确定哪些脚本需要同步加载。 .wait()告诉LAB在加载和包含.wait()之前的所有内容之前不再发出任何脚本请求。

答案 1 :(得分:0)

您可能想要检查:http://www.html5rocks.com/en/tutorials/webcomponents/imports/

这是一种新方法(使用不受支持的浏览器的polyfill),允许调用包含所有资源的单个HTML文件。

相关问题