locked
Scoping Javascript redirects in WSS 3.0 SP2?? RRS feed

  • Question

  • We don't have any custom master pages so I will put jQuery into the HEAD of the master page (contrary to accepted wisdom, usually it goes at the bottom of the page).

    How do I know where to put Javascript calls so they only affect:

    1) the primary (top) home page

    2) the home page and all pages of any SUB-site (e.g. one of the tabs on the top row from the home page)

    The script I need to place is to redirect specific users either to a specific sub-site (tab) from the home page or away from certain sub-sites to a different specific sub-site (tab).

    And how best to place the scripts?? if I can't put them in _layouts like with jQuery?? CEWP, what??

    I'm accustomed to working with normal websites not SharePoint websites!! :) :)

    Thank you, Tom

    Tuesday, September 18, 2012 3:44 PM

Answers

  • Hi tlyczko2,

    Yes, you can add your JavaScript to the head in the master page so that it will run when page opens.

    From your requirement, the script only needs to run on Home page of every site and subsite. So we can use window.location.href to get current URL. If the current URL contains “Home.aspx”, then check if we need to redirect user to another page according to current login user.

    To get current login user, we can use SPGetCurrentUser function in SPServices jQuery library.

    Thanks & Regards,
    Emir Liu
    TechNet Subscriber Support in forum
    If you have any feedback on our support, please contact
    tnmff@microsoft.com


    Emir Liu

    TechNet Community Support

    Wednesday, September 19, 2012 3:27 AM

All replies

  • Hi tlyczko2,

    Yes, you can add your JavaScript to the head in the master page so that it will run when page opens.

    From your requirement, the script only needs to run on Home page of every site and subsite. So we can use window.location.href to get current URL. If the current URL contains “Home.aspx”, then check if we need to redirect user to another page according to current login user.

    To get current login user, we can use SPGetCurrentUser function in SPServices jQuery library.

    Thanks & Regards,
    Emir Liu
    TechNet Subscriber Support in forum
    If you have any feedback on our support, please contact
    tnmff@microsoft.com


    Emir Liu

    TechNet Community Support

    Wednesday, September 19, 2012 3:27 AM
  • Almost. Here's what needs to happen.

    Site has its main home page, then each subsite has a home page, and the desired user must be redirected to a subsite within a subsite.

    Using the above solution, the user will be redirected to their own home page repeatedly, how to prevent this??

    Also, we do not want to redirect the desired user off certain other subsite pages, therefore globally checking for home.aspx is not appropriate...

    Any other suggestions??

    Thank you, Tom

    Wednesday, September 19, 2012 12:25 PM
  • Hi,

    Thanks for your reply.

    Instead of only check the "Home.aspx" string, we can check whole URL string.

    If current URL = whole top site URL or those certain site pages,
    and If current login user is the desired user that need to redirect to subsite,
    then redirect.

    And we can use SPServices to get current login user as I already mentioned in my first reply.

    Thanks & regards,
    Emir


    Emir Liu

    TechNet Community Support


    • Edited by Emir Liu Thursday, September 20, 2012 11:17 AM
    Thursday, September 20, 2012 11:17 AM
  • I already thought of this -- with a zillion URLs to check before allowing the particular user access it could be quite slow...regexes or partial URL string checking may help (e.g. if url string contains x or y or z else...)

    I have NOT been able to find how to make a Javascript apply to ONE and only one particular subsite (e.g. one of the tabs on the home page) or to a subsite within a subsite -- HOW is this done?? CEWPs are possible but take forever to implement because they are page-specific?? not site-specific??

    Thank you, Tom

    Thursday, September 20, 2012 12:47 PM
  • Hi tlyczko2,

    If code needs to apply to many sites and subsites, we can add the script to the master page on top site and inherit all subsites to use this master page.

    If there are not too many site need to apply the script, you can add the script to every Home.aspx page for each sites. This way, there is no need to current URL or site, only need to get current login user.

    Open the Home.aspx page and find the <asp:Content ...></asp:Content> control, put your script within it.

    Thanks & Regards,
    Emir


    Emir Liu

    TechNet Community Support

    Friday, September 21, 2012 9:40 AM