javascript indexOf 检查 if 语句

标签 javascript if-statement indexof

让这段代码工作有一些困难。本质上,我想检查引用 url 是否来自/mobile 目录,如果不是,并且屏幕是我想重定向到移动网站的移动设备。

<script type="text/javascript">
if(window.location.href.indexOf("document.write(document.referrer)") > -1 &&
    screen.width <= 699) {
    document.location = "/mobile/mobile_home.asp";
}

</script>

代码目前放在主home.asp的头部。

最佳答案

试试这个

if(document.referrer.indexOf('/mobile') > -1 && screen.width < 700) {
}

关于javascript indexOf 检查 if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36180212/

相关文章:

javascript - AngularJS 的 $routeProvider templateUrl 总是使用 Express 返回 404

javascript - 选择 div 中的特定元素?

java - Tapestry 使用 Java 表达式转换成 <t :if> component

javascript - 弄清楚如何为诸如push、indexOf之类的函数设置动态变量的问题

javascript - 条形图缓慢放大/缩小 - AmCharts

php - 如何在 PHP 中从 jQuery.Post() 检索数据?

c++ - 在 if 语句中声明类变量

ruby-on-rails - Current_user && 用户个人资料

javascript - 显示投票数最多的数组

java - 字符串数组中的 indexOf