Help Center: redirecting non-agents to another Locale with JavaScript
I want to redirect all non-agents (end-users and anonymous visitors) to /en-gb/ when they visit /en-us/.
$(document).ready(function redirectENUS() {
if (HelpCenter.user.locale == "en-us" && (HelpCenter.user.role == "anonymous" || HelpCenter.user.role == "manager" || HelpCenter.user.role == "end_user")) {
// window.location = "http://subdomain.example.com/hc/en-gb";
window.location.replace("/hc/en-gb/");
}
});
It only works in Preview Mode, though, or when logged in as an agent. If I'm logged out or try to test it in incognito mode, nothing happens.
What am I doing wrong? Thanks in advance!
-
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
-
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 :-)
-
Could https be an issue?
-
Nope! Also tried that one, but to no avail.
-
Sorry... i'm out of ideas... we need a programmer on this one :-)
-
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"
}
}); -
...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!
-
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");
}
}); -
Hi Alex, thanks for the input... unfortunately it doesn't seem to work, either!
-
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.
-
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!
-
Yeah, that would do it.
I'm glad you got it :)
Iniciar sesión para dejar un comentario.
12 Comentarios