Several important and interesting JavaScript Functions in SharePoint

Source: Internet
Author: User

1: _ spbodyonloadfunctionnames ('functionname ')

The main function of this function is to load the specified JS function. The function name is passed in through the string.
For example, on the dispform page of a list, there are two close buttons. If we want to click them, instead of closing them, the prompt "cannot close" is displayed, if this change does not affect other lists, you can use this function. The method is as follows:
Add a content editorial component to dispform. (If you cannot edit this page, add & displaymode = design to the address bar to query parameters)
Enter the JS script as follows:

1 < Script Type = " Text/JavaScript " Language = " Javascript " >
2 Function Resetclosebutton ()
3 {
4 VaR Btns = Document. getelementsbytagname ( ' Input ' );
5 VaR Count = Btns. length;
6 For ( VaR I = 0 ; I < Count; I ++ )
7 {
8 VaR BTN = Btns [I];
9 If (BTN. type. tolowercase () ! = ' Button ' )
10 {Continue;}
11 VaR ID = BTN. Id. tolowercase ();
12 If (Id. indexof ( ' Goback ' ) ! =- 1 )
13 {
14 BTN. onclick = Function () {'It cannot be closed!');
15}
16 }
17 }
18 _ Spbodyonloadfunctionnames. Push ( ' Resetclosebutton ' );
19 < / SCRIPT>

 

For other information, see init. js under c: \ Program Files \ common files \ microsoft shared \ Web Server Extensions \ 12 \ template \ layouts \ 2052.

 

Custom_adddoclibmenuitems (M, CTX) | custom_addlistmenuitems (M, CTX)
These two functions are used to add their own drop-down menus to the document library or list.
Prototype:
If (typeof (custom_adddoclibmenuitems )! = "Undefined ")
{
If (custom_adddoclibmenuitems (M, CTX ))
Return;
}
It can be seen that if custom_adddoclibmenuitems returns true, the menus displayed on the page will be completely customized.
If false is returned, in addition to adding a custom menu, the menu of the SP is displayed.
Its Parameter m represents the current menu object, and CTX should return the current context object, right?
Example:

<Script language = "JavaScript">
Function custom_adddoclibmenuitems (M, CTX)
{
VaR strdisplaytext = "Hi! ";
VaR straction = "javascript: Alert ('Hello! ')";

VaR strimagepath = "";

Camopt (M, strdisplaytext, straction, strimagepath );
Camsep (m );
Return true;
}
</SCRIPT>
--- It is particularly interesting that through this function, the menu you add can also be multi-level ~~~
The function that adds menus with sub-menus seems to be casubm.
For specific functions, see:
C: \ Program Files \ common files \ microsoft shared \ Web Server Extensions \ 12 \ template \ layouts \ 2052 core. js

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.