How to Add onLoad JavaScript event in SharePoint?
来源:互联网 发布:java hadoop实例 编辑:程序博客网 时间:2024/06/06 04:38
How to Add onLoad JavaScript event in SharePoint?
SharePoint provides a JavaScript array “_spBodyOnLoadFunctionNames”, any function to be executed onLoad needs to be added to this array e.g.
_spBodyOnLoadFunctionNames.push("ExecuteMyFunctionOnLoad");
Now, why does your JavaScript function doesn’t execute if you just register it
with ClientScript.RegisterStartupScript?
Actually, content pages can’t execute JavaScript function on body load, reason; content pages can’t directly add a function to the body’s OnLoad event if master page contains the <body> element (which is mostly true).
This array is basically a part of init.js located in “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\”. If you open the javascript file, you will notice the page onLoad event is handled by function _spBodyOnLoadWrapper, which further calls ProcessDefaultOnLoad, and this function executes all the function names added in array "_spBodyOnLoadFunctionNames".function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}}}
addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
addLoadEvent(function() {
/* more code to run on page load */
}
);
_spBodyOnLoadFunctionNames.push("ExecuteMyFunctionOnLoad");
Now, why does your JavaScript function doesn’t execute if you just register it
with ClientScript.RegisterStartupScript?
Actually, content pages can’t execute JavaScript function on body load, reason; content pages can’t directly add a function to the body’s OnLoad event if master page contains the <body> element (which is mostly true).
This array is basically a part of init.js located in “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\”. If you open the javascript file, you will notice the page onLoad event is handled by function _spBodyOnLoadWrapper, which further calls ProcessDefaultOnLoad, and this function executes all the function names added in array "_spBodyOnLoadFunctionNames".
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}}}
addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
addLoadEvent(function() {
/* more code to run on page load */
}
);
- How to Add onLoad JavaScript event in SharePoint?
- how to add Javascript and CSS in page layout with sharepoint 2013
- How to add event listener to div
- How to redirect to a Custom Page for Event Receiver in SharePoint 2010
- How to add event for usercontorl ?
- Prepare to deploy SharePoint add-in
- Mootools add window onload event
- How to open PDF files in sharepoint
- How to Create Mysite in SharePoint 2010
- how to trigger event in program
- How to add swap space in Linux
- How to add Snap-in (扩展Powershell)
- How to add new partition in centos
- How to add route in Linux
- 【skill】How to add codes in csdn ?
- How to add user in gerrit
- How To Add Bookmark (mark) In Pycharm
- How To Add Bookmark (mark) In Pycharm
- SQL Server 远程链接服务器详细配置【转载】
- CONST
- android4.0 及以上 版本 wifi 和 蓝牙不显示 原因
- js调用后台方法
- 获取EXE文件版本。
- How to Add onLoad JavaScript event in SharePoint?
- 01背包一维
- 取石子游戏
- 仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表't_ArticleFiles'中的标识列指定显式值。
- monkey自动化测试
- STL中的map简单详解
- EHT 开发框架 Form 表单动态绑定的实现
- MODBUS协议 一种问答方式的通信协议
- 有效用户id, 实际用户id