Help Center: redirecting non-agents to another Locale with JavaScript

12 Comentarios

  • Alex Culligan
    Acciones de comentarios Permalink

    Try this:

    $(document).ready(function redirectENUS() {
    var fromZ = window.location.href;
    if (fromZ === "https://subdomain.zendesk.com/hc/en-us" && (HelpCenter.user.role == "anonymous" || HelpCenter.user.role == "end_user")) {
    window.location.replace("https://subdomain.example.com/hc/en-gb");
    }
    });

     

     

    2
  • Pedro Rodrigues
    Acciones de comentarios Permalink

    Got it! It was the "https".

    Simplified:

    $(document).ready(function redirectENUS() {
         if ((window.location.href === "http://subdomain.zendesk.com/hc/en-us") && (HelpCenter.user.role == "anonymous" || HelpCenter.user.role == "end_user")) {
           window.location.replace("http://subdomain.zendesk.com/hc/en-gb");
          }
    });

    Many thanks for your help!

    2
  • Alex Culligan
    Acciones de comentarios Permalink

    Weird... it works for me. Make sure that you're adding that at the top of the JS page, save the changes, publish the changes, then test in a different browser. You won't see it work if you try to preview it before publishing.

    1
  • Carsten Falborg
    Acciones de comentarios Permalink

    Hi

    I am no programmer, but it seems that the user.role's isn't necessary for your script to work?

    You also need to add the full URL in the location.replace command: http://www.w3schools.com/jsref/met_loc_replace.asp 

    0
  • Pedro Rodrigues
    Acciones de comentarios Permalink

    Hi Carsten,

    Indeed HelpCenter.user.role == "manager" isn't necessary. I was just using it to Preview results.

    However, I do need the other user.role restrictions: I want agents and managers to be able to visit/use the en-us HC, just not end-users and anonymous visitors.

    The behaviour is the same regardless of having the complete URL. I have tried several options:

    window.location = "http://subdomain.example.com/hc/en-gb";
    window.location = "/hc/en-gb";
    window.location.replace("/hc/en-gb/");
    window.location.replace("http://subdomain.example.com/hc/en-gb");

    ... and still nothing.

    I appreciate your input, though. If you have any other ideas/hints, please do send them my way :-)

    0
  • Carsten Falborg
    Acciones de comentarios Permalink

    Could https be an issue?

    0
  • Pedro Rodrigues
    Acciones de comentarios Permalink

    Nope! Also tried that one, but to no avail.

    0
  • Carsten Falborg
    Acciones de comentarios Permalink

    Sorry... i'm out of ideas... we need a programmer on this one :-)

    0
  • Pedro Rodrigues
    Acciones de comentarios Permalink

    Hehe, it seems like it - thanks a lot, Carsten.

    Also tried:

    $(document).ready(function redirectENUS() {
    var fromZ = document.referrer;
    if (fromZ === "http://subdomain.example.com/hc/en-us" && (HelpCenter.user.role == "anonymous" || HelpCenter.user.role == "end_user")) {
    window.location = "http://subdomain.example.com/hc/en-gb"
    }  
    });
    0
  • Pedro Rodrigues
    Acciones de comentarios Permalink

    ...as well as adding the following code to the top of my Home Page HTML (as per Anna Everson's post here).

    <script type="text/javascript">  
    from = document.referrer;   
    if (from === "http://subdomain.example.com/hc/en-us" && (HelpCenter.user.role == "anonymous" || HelpCenter.user.role == "end_user")) {  
    window.location = "http://subdomain.example.com/hc/en-gb"  
    }  
    </script>

    Still not working!

    0
  • Pedro Rodrigues
    Acciones de comentarios Permalink

    Hi Alex, thanks for the input... unfortunately it doesn't seem to work, either!

    0
  • Alex Culligan
    Acciones de comentarios Permalink

    Yeah, that would do it.
    I'm glad you got it :)

    0

Iniciar sesión para dejar un comentario.

Tecnología de Zendesk