自定义母版页内引用的外部JavaScript文件未调用(触发) [英] External JavaScript file referred inside the custom master page is not getting called (fired)

查看:42
本文介绍了自定义母版页内引用的外部JavaScript文件未调用(触发)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个简单的JavaScript文件,其中包含"Hello World"我保存在样式库"中的警报库.

如果将代码粘贴到CEWP中,我会在页面加载时收到警报消息,但是当我在自定义母版页中引用该代码时,该消息不会被调用.

通过查看页面源代码",我可以在浏览器上看到正确的文件路径.

以下是我在< HEAD>内部进行尝试的不同方法.母版页标签,但没有语法可用.

< head>

  1.< script type ="text/javascript" src =〜SiteCollection/样式库/alert.js" runat =服务器" ></script>

2. < SharePoint:ScriptLink  ID ="ScriptLink4"; language ="javascript"名称=〜SiteCollection/样式库/alert.js" runat =服务器" OnDemand ="false". LoadAfterUI ="true". Localizable ="false" />

3.  < link id =" Link1" href =" ........../Style Library/alert.js" runat =服务器" type ="text/script" />

</head>

任何人都可以帮助我哪里做错了,我将代码粘贴在</HEAD>结束标记的正上方.部分.



解决方案

尝试为此使用根路径.

例如(由于我启用了发布功能,因此我编辑masterpage.html,在这种情况下,您似乎尚未启用此功能,请尝试根据情况将src替换为'/Style Library/alert.js'):


最好的问候,


Hi All,

I have simple JavaScript file having "Hello World" alert which I kept inside the "Style Library" library.

I get the alert message on page load if I paste the code into the CEWP, but it is not getting called when I refer it inside our custom master page.

I can see the correct file path on browser by going "View page source".

Below are different ways i am trying inside the <HEAD> tag of master page but none of the syntax is working.

<head>

 1. <script type="text/javascript" src="~SiteCollection/Style Library/alert.js" runat="server" ></script>

2. <SharePoint:ScriptLink  ID="ScriptLink4" language="javascript" Name="~SiteCollection/Style Library/alert.js" runat="server" OnDemand="false" LoadAfterUI="true" Localizable="false" />

3.  <link id="Link1" href="........../Style Library/alert.js" runat="server" type="text/script" />

</head>

Can anyone help me where i am doing wrong, i pasted the code just above the closing tag of </HEAD> section.



解决方案

Hi,

Try to use root path for this.

For example( as I enabled publishing feature so I edit masterpage.html, seems you haven’t enable this feature, in this case, try to replace the src as ‘/Style Library/alert.js’ for your case ):


Best Regards,

Lee


这篇关于自定义母版页内引用的外部JavaScript文件未调用(触发)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆