1

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.

3

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>
1

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.

0

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.

  • 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. – Jeroen Ritmeijer - Muhimbi Feb 15 '11 at 8:58
0

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy