简体   繁体   English

JavaScript 将别名重定向到域

[英]JavaScript redirect alias to domain

How do I redirect the alias "u144w" to the domain " https://google.com.br " according to the var??如何根据 var 将别名“u144w”重定向到域“ https://google.com.br ”? Over time I will add more aliases and domains there, but I can't do a window.location that can take the alias from the URL, and redirect to the domain, what should I do?随着时间的推移,我将在那里添加更多的别名和域,但我不能做一个 window.location 可以从 URL 获取别名并重定向到域,我该怎么办? "Location.pathname" will take the alias, then the "getlink" function should look for that alias and its due domain to which it will redirect, and "location.href" will do the work of redirecting. “Location.pathname”将采用别名,然后“getlink”function 应查找该别名及其将重定向到的应有域,“location.href”将完成重定向工作。 But I am not able to do this, the most I can use is HTML and JavaScript, and no PHP or MySQL.但我不能这样做,我最多可以使用 HTML 和 JavaScript,没有 PHP 或 Z62A514B9571DCCABB39

<script type="text/javascript">
if(location.pathname == getlink());
{
    function getlink(){
        var links = {
            "u144w": "https://google.com.br",
    };
    window.location.href == getlink();
}
</script>

If I understand you correctly this should work:如果我理解正确,这应该有效:

<script type="text/javascript">
  var alias_mapping = {
    "u144w": "https://google.com.br"
  }
  if(Object.keys(alias_mapping).includes(location.pathname)){
    window.location.href == alias_mapping[location.pathname];
  }
</script>

To add more aliases just extend alias_mapping.要添加更多别名,只需扩展 alias_mapping。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM