木子屋 Dnawo's BLOG

打造不被Google弹出式窗口拦截器Kill的广告

👤 dnawo 📅 2007-09-19 👁 6274 👍 0 💬 0 🔄 本站原创
解读Google弹出式窗口拦截器设计原则

我们先来做一个测试:

HTML
<html>
</head>
<body>
<script language="javascript">
document.write("<a href=\"http:\/\/www.hao123.com/\" target=\"_blank\" onClick=\"window.open('http:\/\/www.mzwu.com/');\">Link1</a>");
document.write("</p><p>");
document.write("<a href=\"http:\/\/www.hao123.com/\" target=\"_self\" onClick=\"window.open('http:\/\/www.mzwu.com/');\">Link2</a>");
</script>
</body>
</html>

是不是很奇怪为什么Links1中的hao123打不开?这还得从Google弹出式窗口拦截器的设计原则说起。在Google工具栏支持中心中对其弹出式窗口拦截器的设计原则说明如下:

Certain user actions, such as clicking on a link, will issue a popup lease. One navigation or the opening of one new window will then clear that lease. A single lease will not permit both a navigation and the opening of a new window.

现在我们来解释一下测试过程中出现两种不同结果的原因:

当点击Links1时,这一特定的用户行为(点击)发出了一次弹出式窗口要求,于是拦截器允许打开mzwu,mzwu打开后要求也随之清除,所以再要在新窗口中打开的hao123就被拦截了。
当点击Links2时,这一特定的用户行为(点击)发出了一次弹出式窗口要求,于是拦截器允许打开mzwu,mzwu打开后要求也随之清除,但这次hao123也随后被打开了,因为这次hao123是在当前窗口中打开,不属于弹出式窗口。

基于上边的测试我们可以得出两点结论:

1.一次特定的用户行为只允许一次弹出式窗口,以此类推
2.对于非弹出式窗口,Google弹出式窗口拦截器不予理会

不被Kill的广告

基于上边两点结论要制作不被Google弹出式窗口拦截器拦截的广告只须让广告不在没有特定用户行为时打开或不用弹出式窗口打开(显示/隐藏层、模态窗口)即可。

HTML
<html>
<head>
<script language="JavaScript">
function findObj(name, doc) 
{
	var x = doc[name];		  
	if (x) return x;  
	if (doc.all)
	{
		x=doc.all[name]; 
	}
	if (x) return x;
	for(var i=0; doc.layers && i < doc.layers.length; i++)
	{
		x=MM_findObj(name, doc.layers[i].document);
	}		  
	if (x) return x;
	if (doc.getElementById)
	{
		x=doc.getElementById(name);
	}			
	return x;
}
function showHideLayers(name, hideOrShow) 
{ 
	var obj = findObj(name, document);
	if (obj.style) 
	{ 
		obj=obj.style; 
		v = (hideOrShow=='show') ? 'visible' : (hideOrShow=='hide') ? 'hidden' : hideOrShow; 
	}
	obj.visibility = v;
}
</script>
</head>
<body>
<div style="position: absolute; top: 0; left:0; width:462; height:351; z-index: 4" id="popupdiv">
<img src="pic/20070919/popup.gif" alt="" name="popupimage" border="0" usemap="#popupmap" id="popupimage" />
    <map name="popupmap" id="popupmap">
      <area href="#" alt="" shape="rect"coords="435,1,460,25" onClick="showHideLayers('popupdiv','hide');popupdiv.style.display='none';" onMouseOver="popupimage.style.cursor='hand';" onMouseOut="popupimage.style.cursor='auto';" />
    </map>
</div>
</body>
</html>

HTML
<html>
<head>
</head>
<body>
<script language="JavaScript">
var xWin = null;

function closePopup()
{
	xWin.hide();
}

function openBadPopUp()
{
	try
	{
		xWin=window.createPopup();
		var vhtml= '<DIV STYLE="position: absolute; top: 0; left:0; width:462; height:351; z-index: 4" id="popupdiv"><img src="pic/20070919/popup.gif" usemap="#popupmap" name="popupimage" alt="" border="0"><map name="popupmap"><area alt="" shape="rect" coords="435,1,460,25" onclick="" onmouseover="popupimage.style.cursor=\'hand\';" onmouseout="popupimage.style.cursor=\'auto\';"></map></DIV>';
		xWin.document.body.innerHTML = vhtml;
		xWin.document.body.onmouseup = closePopup;
		xWin.show(200, 200, 462, 351);
	}
	catch (er)
	{
	}
}
window.onload = openBadPopUp()
</script>
</body>
</html>

HTML
<html>
<head>
</head>
<body>
<script language="javascript">
function openBadPopUp()
{
	try
	{
		var xWin1=window.showModelessDialog("pic/20070919/popup.gif", "", "dialogLeft:20px; dialogTop:20px");
		var xWin2=window.showModalDialog("pic/20070919/popup.gif", "", "dialogLeft:200px; dialogTop:200px");
	}
	catch (er)
	{
	}
}
window.onload = openBadPopUp()
</script>
</body>
</html>

评论(0)

暂无评论。

计算题
评论需审核通过后显示
← 上一篇 ImportExportFavorites 导入或导出收藏夹 下一篇 → 多个函数验证同一表单