SharePoint [ribbon series]-09. How to make user-defined ribbon reference external JavaScript files

Source: Internet
Author: User

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

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.