现在越来越多的浏览器有拦截弹出窗口的功能。广告弹出来给拦掉了就无所谓,要是客户在付款时给拦掉了可就不能乱算了。

Gmail的“哎呀”算是经典,可是,前天心云给出了更帅的提示=。= 记得打开浏览器拦截后 测试一下,在线阅读器里不知道代码会不会给过滤。。代码在下边,其实没什么技术含量滴。挖哈哈。。。

window._open=window.open;
window.open=function(sURL,sName,sFeatures,bReplace){
  if(sName==undefined){sName="_blank"};
  if(sFeatures==undefined){sFeatures=""};
  if(bReplace==undefined){bReplace=false};
  var win=window._open(sURL,sName,sFeatures,bReplace);
  if(!win){
    alert('天啦!你的机器上竟然有软件拦截弹出窗口耶,好讨厌哦,人家不来了啦!快去掉嘛~~555~');
    return false;
  }
  return true;
}

=。= 重写window.open写了两天都没有想到更好的办法,参数要一个一个加,第四个参数,似乎只是为了不被back回去,例如:

window.open("a.html","a");
window.open("b.html","a","",true);

打开的b.html是没有后退可以按滴,MSDN有说明

Optional. Boolean that specifies whether the sURL creates a new entry or replaces the current entry in the window’s history list. This parameter only takes effect if the sURL is loaded into the same window.

  • true sURL replaces the current document in the history list
  • false sURL creates a new entry in the history list.

Creative Commons License

共有 9 条评论

  1. Trackback fireyy blog » [我的收藏]2007年11月19日(3)

    [...] window.open被浏览器拦截后的自定义提示 [...]

  2. mm

    为什么我开了我的浏览器拦截还是没有看到可爱的提示:(

  3. aoao

    @mm 纯粹的样子。。 你的浏览器还没拦截到我的弹窗。^^

  4. lin516

    window.open打开的窗口IE会自动加上url地址,不知道这个有办法去掉吗?

  5. aoao

    @lin516 听不懂你的问题=。=

  6. lin516

    可能你没注意到,经常用window.open打开打开的页面,如果设置了窗口大小等其它属性,IE6会自动在页面的标题中加上这个页面的地址,然后才显示标题文字

  7. 闲耘

    看到这个好代码,不免多手改了一下。
    window.open = function(u, t, f, r){
    var w=window._open(u, t||”_blank”, f||”", r||false);
    if(!w){
    alert(’天啦!你的机器上竟然有软件拦截弹出窗口耶,好讨厌哦,人家不来了啦!快去掉嘛~~555~’); // from other’s funny.
    }
    return w;
    };

  8. gxf

    天啦!你的机器上竟然有软件拦截弹出窗口耶,好讨厌哦,人家不来了啦!快去掉嘛~~555~
    –昏倒!

  9. soncy

    天啦!你的机器上竟然有软件拦截弹出窗口耶,好讨厌哦,人家不来了啦!快去掉嘛~~555~
    被雷到了~

发表评论

(必填)

(必填)

 评论仅支持"a、abbr、strong、em、blockquote、code"几个简单的标签