当前位置: 首页 > 图文教程 > 网络编程 > Javascript > javascript背投广告代码的完善

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 javascript背投广告代码的完善


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 209 ::
收藏到网摘: n/a

对于背投广告的原理来说并没有什么难度,无非打开的窗口失去焦点(blur),而原来页面得到焦点(focus)。但对于流行的浏览器来说,如果非用户行为的弹出窗口(即 onload 时,直接window.open ),会被浏览器默认拦截。 背投广告,既然被称为广告,那如何才能让广告主的钱花得实在,花得乐意呢?
我们可以增加判断,如果该弹出窗口被浏览器拦截,则只要用户点击页面就触发 window.open 事件,这样一般不会拦截,浏览器会认为这是用户的默认行为。
代码可编写如下:
复制代码 代码如下:

var $E = YAHOO.util.Event;
var adPopup;
var popAd = function(sURL,sName,sFeatures,bReplace) {
if (adPopup) return;
if(sName == undefined) {
sName = '_blank';
};
if(sFeatures == undefined) {
sFeatures = '';
};
if(bReplace == undefined) {
bReplace = false;
};
adPopup = window.open(sURL,sTarget,sFeatures,bReplace);
adPopup.blur();
adPopup.opener.focus();
$E.removeListener(document.body, 'click', arguments.callee);
}
try {
popAd();
} catch (e) {
$E.on(document.body, 'click', popAd);
}

当然如果用户浏览器安装了拦截插件,那很有可能不会弹出(比如 Firefox 的 noscript 插件,就不允许任何弹出窗)。方法不是绝对的,也不是最好的,只是用最少的时间来做最效率的事情。
PS:可以通过模拟 form 提交的方式来弹出窗口,穿越性(相对于一般拦截弹窗的插件)很好,不过无法设置 sFeatures 参数内容