开发者

JQuery Path location

开发者 https://www.devze.com 2023-01-29 20:07 出处:网络
am 开发者_C百科using Asp.Net C# 2.0. My website is working fine in local. Website contains 2 js files included in master page.It works fine in local environment, but when i publish my website i get \"

am 开发者_C百科using Asp.Net C# 2.0. My website is working fine in local. Website contains 2 js files included in master page. It works fine in local environment, but when i publish my website i get "Object expected" error on page load, and thus the js functions are not working in published website.

Currently I am writing:

 <script src="/javascripts/jquery.hotkeys-0.7.9.js" type="text/javascript"></script>

in the master page.

Looking forward for help.


Try to use ResolveUrl method like this:

<script src='<%=ResolveUrl("~/javascripts/jquery.hotkeys-0.7.9.js") %>' type="text/javascript"></script>


I believe that there are direcories in your application. Example: ROOT foldera file1.aspx file2.aspx masterpage

assuming file1.aspx and file2.aspx use masterpage, your js link will be rendered different. file1.aspx will look for the js in: ROOT/foldera/javascripts/jquery.hotkeys-0.7.9.js file2.aspx will look for the js in: ROOT/javascripts/jquery.hotkeys-0.7.9.js

in order to solve this you have several options: 1. use ResolveUrl as Fasih Hansmukh suggested. 2. put the script under ScriptManager tag:

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Path="~/javascripts/jquery.hotkeys-0.7.9.js" />
    </Scripts>
</asp:ScriptManager>

Good Luck!


I attach the jscript on the master page programatically,

AppendScript("/javascripts/jquery.hotkeys-0.7.9.js");

private void AppendScript(string jsURL)
{
    HtmlGenericControl myJs = new HtmlGenericControl();

    myJs.TagName = "script";
    myJs.Attributes.Add("type", "text/javascript");
    myJs.Attributes.Add("src", HttpRuntime.AppDomainAppVirtualPath + (jsURL.Substring(0, 1) != "/" ? "/" + jsURL : jsURL));
    this.Header.Controls.Add(myJs);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消