【问题标题】:How do I redirect the user if they get a certain string如果他们得到某个字符串,我如何重定向用户
【发布时间】:2013-01-21 22:24:55
【问题描述】:

我有一些 JavaScript 代码在屏幕上打印随机字符串,而不是随机数字和字母,只是我创建的单词。所以我需要它,所以如果它随机选择某个字符串,它会将您重定向到不同的页面。

【问题讨论】:

  • 向我们展示您正在使用的代码。

标签: javascript html css string random


【解决方案1】:
if (randomString == 'patternString') {
   window.location.href = 'http://google.com';
}

【讨论】:

    【解决方案2】:
    window.location.href = 'https://www.google.com/search?q=' + encodeURIComponent(randomString);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-15
      • 2011-03-14
      • 2017-04-24
      • 1970-01-01
      • 2015-10-22
      • 2013-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多