Use Javascript Redirects to hide SharePoint default sites

July 18, 2008 at 5:36 pm 4 comments

I’ve been working diligently on the new web application and I needed to record this little tip. I am creating new forms for entering items and viewing of lists, but users can still get to the default SharePoint pages through areas I haven’t customised – the search results is currently the easiest – but also the bread crumb trail on some pages.

To get around this, I am using the Javascript redirect and placing it in the <head> section of the default SharePoint pages for my lists – so even if I miss a link somewhere – the user never sees the SharePoint page. They are automaticaly redirected to the custom form I spent hours designing. After all, they really do need to see my spectacular work don’t they?

I started by creating a Content Place Holder in the master page so it would be available to all pages – I find this useful for inserting ANY Javascript and not just for this tip. Just before the closing </head> tag in the master page, I added the following line to create the place holder:

<asp:ContentPlaceHolder id=”PlaceHolderAdditionalPageHead” runat=”server”/>

Now, this is probably pretty basic to some of you, but others might not know how to add these to the master page. Any code on a SharePoint page that contains content place holders, must be in a content place holder – so don’t just try to slap the Javascript on the aspx page.

On the aspx page, for example dispform.aspx, I inserted the following code – just after the declarations at the top of the page – I want it to be the first thing that loads on the page:

<asp:Content ContentPlaceHolderID=”PlaceHolderAdditionalPageHead” runat=”server”>
 <script type=”text/javascript”><!–
location.href = ‘http://sharepointsite/sites/webapplication/Lists/List name/customform.aspx’;
// –></script> 

As you can see from the code, the Javascript just changes the location.href for the page to a new address and the user is instantly redirected. Hope this helps to hide any nasty SharePoint pages that jump in and ruin your nice designs.

Thanks for Reading


Entry filed under: SharePoint Designer, SharePoint Tips and Tricks, Web Application. Tags: , , , , .

Site Theme Change Update: AWOL

4 Comments Add your own

  • 1. AutoSponge  |  July 18, 2008 at 6:21 pm

    Beware the hackers like me who can tell you didn’t use the default form and turn off javascript to get to your default form. Then we can turn JS back on to submit data you don’t want us to know is there.

    Or, I can just hit the web service that allows me to submit data not on the form.

  • 2. ThiNg  |  July 18, 2008 at 6:26 pm

    Oooh I like this kind of response. This is an area that I am well aware of, and one of the reasons we decided to go with SharePoint. Hopefully AutoSponge can elaborate on this a bit more.

    Can I assume that all the users in my web application are controlled by SharePoint security – so if they get to the form and create an item it will still record who did it and when?

    As far as my example goes, I am only hiding the design aspect of the form from the user – I am giving them full functionality at the current time – but I may want to disable stuff in the future – so I anyone knows the correct answer here, let me know…

  • 3. sharavathi  |  September 4, 2008 at 2:30 pm

    Thanks for this solution.
    I want to pass the list items as parameter through this URL(through new URL).
    can you give some suggestions on this issue.
    How i can get the list items using javascript code and pass those items through URL.

    thanks in advance,

  • 4. Recent Links Tagged With "masterpages" - JabberTags  |  December 12, 2008 at 4:34 am

    […] public links >> masterpages Use Javascript Redirects to hide SharePoint default sites Saved by SinoMelo on Thu 20-11-2008 Unity IoC and ASP.NET Part II Screencast with Appearances by […]


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed

%d bloggers like this: