2007-08-31
关于页面unload之后发送一个请求的问题
现在想在页面刷新或者页面跳转的时候,发一个http请求,使用如下方法,有时候可以有时候请求
发不出去,在httpwatch下面会出现Aborted的信息,请求没有发送出去。
-----代码---------------------start
/**
* 用户关闭页面的时候,给服务器发一个http链接
*/
function onlineWindowUnload() {
if (document.callUrlInnerFrame)
{
document.callUrlInnerFrame.location.href=“http://www.javaeye.com”;
//延时一段时间
var i ;
for (i = 0 ;i < 200 ;i++) {
i = i + 1;
}
}
}
window.onunload =onlineWindowUnload;
-----代码---------------------end
有没有什么方法,可以让页面在关闭的时候,可以sleep一段时间让我这个请求能够顺利发送出去?
发不出去,在httpwatch下面会出现Aborted的信息,请求没有发送出去。
-----代码---------------------start
/**
* 用户关闭页面的时候,给服务器发一个http链接
*/
function onlineWindowUnload() {
if (document.callUrlInnerFrame)
{
document.callUrlInnerFrame.location.href=“http://www.javaeye.com”;
//延时一段时间
var i ;
for (i = 0 ;i < 200 ;i++) {
i = i + 1;
}
}
}
window.onunload =onlineWindowUnload;
-----代码---------------------end
有没有什么方法,可以让页面在关闭的时候,可以sleep一段时间让我这个请求能够顺利发送出去?
- 21:10
- 浏览 (817)
- 论坛浏览 (1108)
- 评论 (3)
- 相关推荐
评论
下面的代码应该有你要的东西。
function as_click () {
urchinTracker ('/asclick');
}
if(typeof window.addEventListener != 'undefined')
{
window.addEventListener('load', adsense_init, false);
}
else if(typeof document.addEventListener != 'undefined')
{
document.addEventListener('load', adsense_init, false);
}
else if(typeof window.attachEvent != 'undefined')
{
window.attachEvent('onload', adsense_init);
}
else
{
if(typeof window.onload == 'function')
{
var existing = onload;
window.onload = function()
{
existing();
adsense_init();
};
}
else
{
window.onload = adsense_init;
}
}
function adsense_init () {
if (document.all) {
var el = document.getElementsByTagName("iframe");
for(var i = 0; i < el.length; i++) {
if(el[i].src.indexOf('googlesyndication.com') > -1) {
el[i].onfocus = as_click;
}
}
} else { window.addEventListener('beforeunload', doPageExit, false);
window.addEventListener('mousemove', getMouse, true);
}
}
var px;
var py;
function getMouse(e) {
px=e.pageX;
py=e.clientY;
}
function findY(obj) {
var y = 0;
while (obj) {
y += obj.offsetTop;
obj = obj.offsetParent;
}
return(y);
}
function findX(obj) {
var x = 0;
while (obj) {
x += obj.offsetLeft;
obj = obj.offsetParent;
}
return(x);
}
function doPageExit(e) {
ad = document.getElementsByTagName("iframe");
for (i=0; i<ad.length; i++) {
var adLeft = findX(ad[i]);
var adTop = findY(ad[i]);
var inFrameX = (px > (adLeft - 10) && px < (parseInt(adLeft) + parseInt(ad[i].width) + 15));
var inFrameY = (py > (adTop - 10) && py < (parseInt(adTop) + parseInt(ad[i].height) + 10));
if (inFrameY && inFrameX) {
urchinTracker('/asclick');
}
}
}
发表评论
该博客是同时发布到论坛的,无法评论在论坛已被锁定的帖子
- 浏览: 8117 次

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
关于mysql latin1编码时候 ...
use utf-8 as table encoding is much bett ...
-- by mathgl -
关于mysql latin1编码时候 ...
这个数据库是多个地方要使用,不止我这一个
-- by hhongq -
关于mysql latin1编码时候 ...
为什么不一开始使用utf8??? 采用latin1用什么好处 能告知一下好吗?
-- by xmvigour -
请教关于文件上传和文件同 ...
最终决定通过硬件解决,使用存储机器。自动同步
-- by hhongq -
请教关于文件上传和文件同 ...
关注这个问题,现在也碰到类似的问题了。关注大家的解决方案。
-- by saharabear






评论排行榜