Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Please tell me where can I write javascript for a sharepoint site and what are the possible ways to write a javascript code for a sharepoint site.

share|improve this question

4 Answers 4

Approach 1 :

You can define your java script code in code behind file and than you can register it using Page.IsClientScriptBlockRegistered as shown below.

private const string strJQueryScript = "<script type=\"text/javascript\">"+
                                         Your Script content here.
                                            "</script>";

Once you created your script you can later use following code in "OnPreRender" method.

protected override void OnPreRender(EventArgs e)
{

if (!Page.IsClientScriptBlockRegistered("jquerythickbox"))
                Page.RegisterClientScriptBlock("jquerythickbox",
                  strJQueryScript);
}

Approach2:

You can place ContentEditorWebPart on the page and write Javascript code there.

Approach3:

Create your javascript file and put it in _Layouts folder. Once you have your javascript file you can modify your master page and register tag as shown below.

<script type="text/javascript" language="javascript" src="/_layouts/YourFolderName/YourFile.js"></script>
share|improve this answer

It can be even easier than the other answers: You can simply put the JavaScript into a Content Editor Web Part. It all depends on what your goals are, e.g., how widely you want to use the script, what it does, etc.

share|improve this answer

If you just want to add some JavaScript to the existing user interface without having to modify your existing pages or solution then check out our free Muhimbi SharePoint Infuser tool.

share|improve this answer
    
Could you please edit this answer to make it clear this is your company's product? It does answer the question directly so I guess isn't technically spam, but clear attribution would help. Thanks! –  Alex Angas Feb 15 '11 at 2:33
    
No worries Alex, I have reworded it. It is a free tool so didn't bother with the attribution. –  Muhimbi Feb 15 '11 at 8:58

Here is a question that I asked on the matter Click Here

As you will see I also made use of a CEWP.......

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.