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

I just want to modify some of the contents on all the SharePoint pages be it adminstration page or some site page or any other page using my script (Javascript) and AJAX code.

My ultimate aim is to show presence (in the same way as sharepoint show lync presence) and some widget (UI) on right click(or mouseover) on my presence pawn. My javascript will connect to my server for getting presence information.

I know if add a webpart I can execute my Javascript on my webpart page but I want to do it on the page.

What do you think if I can do something like above. Any ideas or suggestion please.

PS. I checked the WSS3.0 installation on ISS, to my surprise there is no static page, I suppose all the pages are created dynamically (may be rendered by some dll to IE on runtime). So I just can't embed my JavaScript so easily on pageload.

share|improve this question

6 Answers 6

The easiest way is just to add the JS to the masterpage.
But if the pages are created with a pagelayout, you can put it in there instead. The advantage with the last one is that only the pages that are created with this pagelayout wil contain the JS, not more than this. If you put it on the masterpage, EVERY page contains the JS.

So I would prefer the pagelayout-option. But it's your choice of course :-)

Extra info: (SP2010)
To activate pagelayouts, you need to activate the following features:
- Sitecollection: SharePoint Server Publishing Infrastructure
- Site: SharePoint Server Publishing

Links

share|improve this answer
    
Do you have some reference or link to some howto for the pageLayout-option?? –  tropicaljava Jul 12 '12 at 9:25
    
It's SharePoint 2010? –  Ruben Herman Jul 12 '12 at 9:25

It depends on how you want to implement it on the site.

If you went this presence script to run on every single page on your site, add the javascript to your masterpage, or if you want it on specific pages, add it to one or more of your pagelayouts - as @Ruben Herman suggests.

There are 3 ways of implementing your scripts.

  1. Is to add the javascript directly in the head tag in the masterpage (just above the PlaceHolder called PlaceHolderAdditonalPageHead) or directly in the PlaceHolderAdditonalPageHead in one or more of your pagelayouts.
  2. (Best practice) Is to add your javascript in a file and upload it to Style Library on the root site, and then reference it as follows: <SharePoint:ScriptLink ID="MyJavascript" runat="server" LoadAfterUI="True" Name="PATH TO SCRIPT FILE HERE" /> according to suggestion 1.
  3. (Best practice) Is similar to suggestion 2, but by adding the .js file to the _layouts folder instead of the Style Library, so that you reference looks as follows: <SharePoint:ScriptLink ID="MyJavascript" runat="server" LoadAfterUI="True" Name="/_layouts/MyJavascript.js" />

Hope this helps.

share|improve this answer
    
Thanks. (Just FYI) I want my script to run on each and every page of SP whether its site, central administration or any other page. The script will pick the list of users from the page and add an status pawn just besides each user using AJAX. Further the script will keep looking for status change event and if status change is received for some user, it will update the status pawn image. –  tropicaljava Jul 12 '12 at 10:26
    
I have no idea if it's plausable to modify Central Admin, but what you want to achieve regarding having the script run on every single page is easily done by one of the 3 ways in my answer. –  Daniel Ziga Jul 12 '12 at 10:36
    
Why runat value is "server". I think my script will run at client side. Isn't it? –  tropicaljava Jul 12 '12 at 11:08
    
@tropicaljava It's a formality. The runat="server"is just a property which has to be there. –  Daniel Ziga Jul 12 '12 at 11:13
    
Fine. I added a sample script and its working. But is it possible to modify the table (Shared Documents table) which shows document Type, name, Modified By column. I am interested in "Modified By" column contents to show presence from my server. –  tropicaljava Jul 12 '12 at 13:38

You might want to consider using delegate controls.

See this blog post for more detail:-

http://www.sharepointnutsandbolts.com/2007/06/using-delegate-control.html

The great thing about delegate controls is that you can just turn on the feature in the site you want to use it in. You don't have to edit any master pages or page layouts.

share|improve this answer

You have several options, but inserting your script (or a file reference to it) directly in the master page (esp. with Designer) is not good practice if you want your snippet to be portable to other sites. I'd rather use Delegate Controls (can be activated on every site) or put it in the Page Layout (will only appear on publishing page of publishing sites).

What's more is that you have a couple of different master pages depending on the page you're on, so you would need to modify all of them if you really want your script everywhere.

Delegate controls are really easy to make and package.

share|improve this answer
    
Sorry I am new to sharepoint but what do you mean by packaging here? Cause what i understand that I need to write some entry/code in the existing master page. –  tropicaljava Jul 12 '12 at 11:11
    
I mean, instead of directly editing the site with SharePoint to insert your script (and you would need to edit each and every site), you can use Visual Studio to package the script into a deployable solution (.WSP file). Then once that is deployed you just activate the feature on each site (or use PowerShell to do all sites at once). It's a bit more work up front but much more scalable (imagine you have 1000 sites!) –  Louis Jul 12 '12 at 12:29

You should definitely use the master page and enter whatever script you like.

http://sharepoint.microsoft.com/Blogs/GetThePoint/Lists/Posts/Post.aspx?ID=386

share|improve this answer

The most comprehensive way to do this is to add a Custom Action with a Location="ScriptLink" attribute to your site. The advantages of this approach over a master page-based approach are:

  • It won't break if your users switch or modify master pages
  • It will work in dialogs

This will work in a sandbox solution as well, so there's no need to deploy code to the server if that's a concern as well.

Here's a link that explains the process to implement this.

share|improve this answer
    
ha, just noticed you are on wss3, so the sandbox approach doesn't apply, but the rest of it does. –  Derek Gusoff Jul 12 '12 at 13:51
    
What do you mean by "It will work in dialogs"? –  tropicaljava Jul 12 '12 at 14:14
    
oh yeah, there are no dialogs in wss3 either. –  Derek Gusoff Jul 13 '12 at 13:06

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.