0

我有一大堆头 javascript,都在一个文件中。其中一个脚本会检查访问者是否已经选择了一种布局格式(普通、平板电脑、移动设备)。如果没有,她/他会被提醒在索引页面上可以做出这样的选择。

但由于该选项是索引页面上描述的第一件事,因此如果请求索引页面本身,则不需要运行该脚本。但是如何防止该特定脚本仅在索引页面上运行?我试过这个

function informVisitor() {
    var layout = readCookie("layout");
    if (((layout == "") || (layout == null)) && (window.location.indexOf("index.php") != 0))
    {alert('Are you using a small device?\n Check the Welcome page for layout options.')}
}
informVisitor();

但 Firebug 说这window.location.indexOf不是一个函数。有可能吗,如果有,怎么做?还是我应该只使用window.location整个 http-url 而忘记本地故事?

4

0 回答 0