[英]Script editor working only in edit page mode
When in edit page mode the script works, but when I stop editing the page the script will not run. 在编辑页面模式下,脚本可以正常工作,但是当我停止编辑页面时,脚本将无法运行。
<script language='javascript' type='text/javascript'>
function FilterOMenu(c, a) {
//Be carefull with overriding SharePoint core functions, for now this will work (September 2016 CU). Ensure you test this every time after installing a SharePoint update.
//SharePoint default (I placed this above, cause it returns.)
if (a == null)
return;
var b = a.tagName == "DIV" ? a.parentNode : a;
//End SharePoint default
//Custom implementation to sort the filter
var fieldInternalName = a.getAttribute("name");
//some sort functions
var ascComparer = function(a,b){return a.text<b.text ? -1:a.text>b.text ? 1 : 0;};
var descComparer = function(a,b){return a.text>b.text ? -1:a.text<b.text ? 1 : 0;};
var ascDateComparer = function(a,b){d1 = Date.parse(a.text);d2 = Date.parse(b.text);return d1<d2 ? -1:d1>d2 ? 1 : 0;};
var descDateComparer = function(a,b){d1 = Date.parse(a.text);d2 = Date.parse(b.text);return d1>d2 ? -1:d1<d2 ? 1 : 0;};
var myCustomSort = {};
//Add the field internal name and give a comparer as value to sort
//As example the title column as your case is
myCustomSort["Kuup_x00e4_ev"] = descDateComparer;
//myCustomSort["Aktiivne"] = ascComparer;
//console.log(myCustomSort["Date"]);
if(typeof c != "undefined" && c != null && typeof myCustomSort[fieldInternalName] != "undefined"){//check if you implemented a custom sort for the current internalname
//select all items that are checkable (the options)
var allSelectableItems = c.querySelectorAll('[checked]');
if(allSelectableItems.length > 0){
var elementInnerhtmls = [];
var htmlToReplace = "";
var htmlToAppend = "";
for(var i = 0;i<allSelectableItems.length;i++)
{
elementInnerhtmls.push({text: allSelectableItems[i].getAttribute("text"),html:allSelectableItems[i].outerHTML});
htmlToReplace += allSelectableItems[i].outerHTML;
}
elementInnerhtmls = elementInnerhtmls.sort(myCustomSort[fieldInternalName]);
for(var i = 0;i<elementInnerhtmls.length;i++)
{
htmlToAppend += elementInnerhtmls[i].html;
}
//replace the original html with the sorted html
c.innerHTML = c.innerHTML.replace(htmlToReplace,htmlToAppend);
}
}
//SharePoint default
OMenu(c, b, null, null, -1)
//End SharePoint default
} </script>
I have the language and type attributes set, but still nothing. 我有语言和类型属性设置,但仍然没有。 Can someone tell me why my publishing page script only runs when I go to edit the page?
有人可以告诉我为什么我的发布页面脚本只在我去编辑页面时运行?
This issue usually occurs in case of the following: 如果出现以下情况,通常会发生此问题:
type=”text/javascript”
. type=”text/javascript”
。 “SP.js”
and “SP.Runtime”
files are not refrenced properly. “SP.js”
和“SP.Runtime”
文件未正确“SP.Runtime”
。 ExecuteOrDelayUntilScriptLoaded
function. ExecuteOrDelayUntilScriptLoaded
函数。 Minimal Download Strategy Feature
is activated. Minimal Download Strategy Feature
已激活。 For more details, check SharePoint 2016: JSOM is only working in Edit Mode 有关更多详细信息,请查看SharePoint 2016:JSOM仅在编辑模式下工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.