In the field of ribboon programming using javaspoint2010, We must encounter how to compile JavaScript code for ribbon controls.
The following is a common code defined by Ribbon:
<Commanduihandlers>
<Commanduihandler command = "ribbon. mytab. mygroup. button_cmd" commandaction = "javascript: Alert ('ribbonjs invoke! ');'/>
</Commanduihandlers>
The commandaction in this Code defines the JavaScript function that the ribbon control will execute. The problem is that in practical applications, our Javascript is far more than just a simple alert function, and we cannot embed a lot of complicated JavaScript code in this ribbon definition, what we need to do should be the same as the following code definition section:
<Commanduihandlers>
<Commanduihandler command = "ribbon. mytab. mygroup. button_cmd" commandaction = "javascript: ribbonbuttonhandler ();"/>
</Commanduihandlers>
Dive into a JavaScript function in commandaction, which is defined in an external Javascript file. So the next question is, how can I let the definition section of ribbon know which external Javascript file should be used for reference?
Fortunately, Sharepoint provides such a way, we only need to add the following code to solve this problem.
<Customaction id = "ribbon. Library. Actions. scripts"
Location = "scriptlink" scriptsrc = "/_ layouts/sharepointproject1/ribbonactions. js"/>
The scriptsrc of this Code specifies the location and file name of the Javascript file to be referenced externally. Of course, we need to create this JavaScript code file named ribbonactions. js in the/_ layouts/sharepointprojects1/directory.
Therefore, the complete code should be as follows:
<Commanduihandlers>
<Commanduihandler command = "ribbon. mytab. mygroup. button_cmd" commandaction = "javascript: ribbonbuttonhandler ();"/>
</Commanduihandlers>
<Elements xmlns = "http://schemas.microsoft.com/?point/">
<Customaction
Id = "ribbon. mytab"
Title = "ribbon sample"
Registrationtype = "list"
Registrationid = "100 ″
Location = "commandui. ribbon. listview">
<Commanduiextension>
<Commanduidefinitions>... </Commanduidefinitions>
<Commanduihandlers>
<Commanduihandler command = "ribbon. mytab. mygroup. button_cmd" commandaction = "javascript: ribbonbuttonhandler ();"/>
</Commanduihandlers>
</Commanduiextension>
</Customaction>
<Customaction id = "ribbon. Library. Actions. scripts"
Location = "scriptlink"
Scriptsrc = "/_ layouts/sharepointproject1/ribbonactions. js"/>
</Elements>
Reprinted: http://www.cnblogs.com/wsdj-ITtech/archive/2012/07/12/2421014.html
In the field of ribboon programming using javaspoint2010, We must encounter how to compile JavaScript code for ribbon controls.
The following is a common code defined by Ribbon:
<Commanduihandlers>
<Commanduihandler command = "ribbon. mytab. mygroup. button_cmd" commandaction = "javascript: Alert ('ribbonjs invoke! ');'/>
</Commanduihandlers>
The commandaction in this Code defines the JavaScript function that the ribbon control will execute. The problem is that in practical applications, our Javascript is far more than just a simple alert function, and we cannot embed a lot of complicated JavaScript code in this ribbon definition, what we need to do should be the same as the following code definition section:
<Commanduihandlers>
<Commanduihandler command = "ribbon. mytab. mygroup. button_cmd" commandaction = "javascript: ribbonbuttonhandler ();"/>
</Commanduihandlers>
Dive into a JavaScript function in commandaction, which is defined in an external Javascript file. So the next question is, how can I let the definition section of ribbon know which external Javascript file should be used for reference?
Fortunately, Sharepoint provides such a way, we only need to add the following code to solve this problem.
<Customaction id = "ribbon. Library. Actions. scripts"
Location = "scriptlink" scriptsrc = "/_ layouts/sharepointproject1/ribbonactions. js"/>
The scriptsrc of this Code specifies the location and file name of the Javascript file to be referenced externally. Of course, we need to create this JavaScript code file named ribbonactions. js in the/_ layouts/sharepointprojects1/directory.
Therefore, the complete code should be as follows:
<Commanduihandlers>
<Commanduihandler command = "ribbon. mytab. mygroup. button_cmd" commandaction = "javascript: ribbonbuttonhandler ();"/>
</Commanduihandlers>
<Elements xmlns = "http://schemas.microsoft.com/?point/">
<Customaction
Id = "ribbon. mytab"
Title = "ribbon sample"
Registrationtype = "list"
Registrationid = "100 ″
Location = "commandui. ribbon. listview">
<Commanduiextension>
<Commanduidefinitions>... </Commanduidefinitions>
<Commanduihandlers>
<Commanduihandler command = "ribbon. mytab. mygroup. button_cmd" commandaction = "javascript: ribbonbuttonhandler ();"/>
</Commanduihandlers>
</Commanduiextension>
</Customaction>
<Customaction id = "ribbon. Library. Actions. scripts"
Location = "scriptlink"
Scriptsrc = "/_ layouts/sharepointproject1/ribbonactions. js"/>
</Elements>
Reprinted: http://www.cnblogs.com/wsdj-ITtech/archive/2012/07/12/2421014.html