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

12 댓글

  • Alex Culligan
    댓글 작업 고유 링크

    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
    댓글 작업 고유 링크

    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
    댓글 작업 고유 링크

    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
    댓글 작업 고유 링크

    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
    댓글 작업 고유 링크

    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
    댓글 작업 고유 링크

    Could https be an issue?

    0
  • Pedro Rodrigues
    댓글 작업 고유 링크

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

    0
  • Carsten Falborg
    댓글 작업 고유 링크

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

    0
  • Pedro Rodrigues
    댓글 작업 고유 링크

    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
    댓글 작업 고유 링크

    ...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
    댓글 작업 고유 링크

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

    0
  • Alex Culligan
    댓글 작업 고유 링크

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

    0

댓글을 남기려면 로그인하세요.

Zendesk 제공