none
Trying to redirect users to new page

    Question

  • I have a small section of a site - 5 pages - that display some reports.

    A set of 5 pages to replace those pages have been developed.

    My thought was to add a content editor web part on each of the old pages that would contain javascript such as:

    <script type=”text/javascript”>

    <!--

    window.location = “http://mysite/sites/us/new_summary.aspx

    //-->

    </script>

    Then I would mark it as hidden. I was expecting that when I visited the page, I would be redirected to the new summary page.

    However, I am not being redirected.

    Is there something else that I need to do to get this to work?

    Thank you.

    Friday, August 29, 2014 12:52 PM

Answers

  • Could you share what the exact code in your txt files looks like? Maybe there's something simple that just needs another set of eyes to spot.

    Here are a couple methods for redirecting a page using JavaScript:

    <script>
         window.location.href = "http://www.bing.com";
    </script>

    or

    <script>
         window.location.redirect("http://www.bing.com");
    </script>
    The latter method prevents the original location from being stored in the browser history, so clicking the "back" button after they're redirected will take the user back to where they came from, rather than back to the redirect page.
    • Marked as answer by lwvirden Friday, August 29, 2014 7:11 PM
    Friday, August 29, 2014 5:14 PM

All replies

  • So, out of the 4 (not 5 as I thought) pages that I have to redirect, I was able to get 3 to do exactly what I wanted.

    I did the same steps:

    1. Page > Edit Page > Add a Web Part > Category > Media and Content > ContentEditorWebPart >Add
    2. Click on “Click here to add new content”. Nothing needs to go here
    3. Click on web part menu (top right corner). Select Edit Web Part
    4. Advanced > Uncheck minimize, close, zone change, connections, editing in personal view
    5. Click Apply
    6. Copy URL of RedirectSummary.txt and  paste into Content Link URL box
    7. Click Apply
    8. Page > Stop Editing

    The only differences for this time are:

    1. the page being edited is in a different location than the other 3

    2. the URL for the .txt file is different

    3. The contents of the .txt has a different URL for the window.location.

    However, this last page won't redirect like the others.

    Does anyone have any ideas on things I could do to identify the situation?

    I tried turning on the developer tool in IE11. There is so much javascript listed that it would be difficult for me to know if there was a reason something was interfering.

    Friday, August 29, 2014 3:33 PM
  • Could you share what the exact code in your txt files looks like? Maybe there's something simple that just needs another set of eyes to spot.

    Here are a couple methods for redirecting a page using JavaScript:

    <script>
         window.location.href = "http://www.bing.com";
    </script>

    or

    <script>
         window.location.redirect("http://www.bing.com");
    </script>
    The latter method prevents the original location from being stored in the browser history, so clicking the "back" button after they're redirected will take the user back to where they came from, rather than back to the redirect page.
    • Marked as answer by lwvirden Friday, August 29, 2014 7:11 PM
    Friday, August 29, 2014 5:14 PM
  • The exact text starts after the Begin text file line.

    ----- Begin text file -----

    <script type=”text/javascript”>
    <!--
    window.location = “http://mysite/sites/US/SitePages/Summary.aspx”
    //-->
    </script>
    

    Friday, August 29, 2014 5:19 PM
  • I don't know whether or not this is important, but this is the URL of the page that won't redirect.

    http://mysite/sites/US/Services/ReportsAndDashboards/ProductionChangesIncidentsReports.aspx

    When I look at all site contact on the Services site, I don't see anything called "ReportsAndDashboards".

    If I go to http://mysite/sites/US/Services/ReportsAndDashboards/

    I find myself at a page that lists a series of ABCReports.aspx pages and ProductionChangesIncidentsReports.aspx is one of the list.

    I am just surprised that the pages are in something called "ReportsAndDashboards" that doesn't show up in SharePoint's All Site Content.

    Could this cause a redirect problem?

    Friday, August 29, 2014 5:27 PM
  • I just tried changing my .txt file to

    <script>

    windows.location.redirect("http://mysite/sites/US/SitePages/Summary.aspx");

    </script>

    and I get the same behavior - no redirection.

    Friday, August 29, 2014 5:30 PM
  •  I just tried replacing the contents of the .txt file with

    This page has moved. Please bookmark the new page once your browser arrives at the new page.
    <meta http-equiv="refresh" content=”10;url=http://mysite/sites/US/SitePages/Summary.aspx>

    and the text appears, but the window does not refresh.

    Friday, August 29, 2014 5:42 PM
  • I just tried changing my .txt file to

    <script>

    windows.location.redirect("http://mysite/sites/US/SitePages/Summary.aspx");

    </script>

    and I get the same behavior - no redirection.


    I'm not sure if this typo is in your actual code or just in the post, but it should be window.location.redirect, not windows.location.redirect
    Friday, August 29, 2014 6:12 PM
  • Re: typo

    Well, to be certain, I tried again with "window.location.redirect" and still get no redirection. Also no errors.

    Friday, August 29, 2014 6:30 PM
  • In case this is important, I am testing with IE 11 and Chrome 36.0.1985.143 m and both fail to redirect with

    <script>
         window.location.redirect("http://www.bing.com");
    </script>

    or

    <script>
         window
    .location.href = "http://www.bing.com";
    </script>

    as the only contents of the file being read by the Content Editor Web Part.

    Friday, August 29, 2014 6:33 PM
  • So, after trying all sorts of things, there was proper alignment of technical gotchas (cache, browser, correct URL, etc. so that the .txt containing

    <script>
         window
    .location.href = "http://www.bing.com";
    </script>

    finally started working.

    Thank you all so much. I have no idea what was causing the earlier issues - but this is one thing that is working now.

    Friday, August 29, 2014 7:11 PM