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

Calling HTML within ASP to call other scripts

本文关键字:调用 其他 脚本 HTML ASP      更新时间:2024-03-02

我正在开发sharepoint,并在我的文件中嵌入了jquery、谷歌图表、角库调用。但是,当我需要添加或删除内容时,返回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页面以包含我想要的脚本,而只需要编辑Script Controller文件。这可能吗?

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

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

脚本管理器

<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()之前的所有内容之前不要再进行任何脚本请求。

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

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