在page layout 中經過 _spBodyOnLoadFunctionNames.push("js 方法名") 的方式實現。javascript
但切記,代碼要放到 PlaceHolderMain 內部執行。java
在page layout PlaceHolderMain 區域內直接寫,或者在該區域引入js文件皆可。。。git
e.g.app
_spBodyOnLoadFunctionNames.push("GenerateRightNavList");
function GenerateRightNavList() { var currurl = location.href; // pages using business page layout if ($("#hidnIsBusinessPageLayOut").length > 0) { var urlparts = currurl.split("/"); if (urlparts != null && urlparts.length > 2) { var itemName = urlparts[urlparts.length - 2]; $("#nav-block>div.widget-header:eq(0)").text(itemName.replace("-", " ")); var filterUrl = currurl.substring(0, currurl.lastIndexOf("/") + 1); //alert($("ul.primary-menu>li.menu-item>a[href^='"+filterUrl+"']").length); $("ul.sub-menu>li.menu-item>a[href^='" + filterUrl + "']").each(function () { $("#menu-shortcodes").append('<li class="menu-item menu-item-type-post_type menu-item-object-page"><a href="' + $(this).attr("href") + '">' + $(this).find("span:eq(0)").text() + '</a></li>'); }); var pstring = ""; var cstring = ""; var itemobj = $("ul.primary-menu>li.menu-item>a[href^='" + filterUrl + "']:eq(0)"); var subitemobj = $("ul.sub-menu>li.menu-item>a[href='" + currurl + "']:eq(0)"); if (itemobj.length > 0) { pstring = $.trim(itemobj.find("span:eq(0)").text()); } if (subitemobj.length > 0) { cstring = $.trim(subitemobj.find("span:eq(0)").text()); } var breadString = pstring + (cstring != "" ? ': ' + cstring : ""); $("#breadcrumbs").append('You are here: <a href="/home">Home</a> / ' + breadString); } } }
orpost
<script type="text/javascript" src="/Scripts/layout.js"></script>
PS:this