location.href和onload [英] location.href and onload

查看:184
本文介绍了location.href和onload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用onload事件加载一系列网址。

我发现onload函数只被调用一次

no无论数组有多大。

这是onload函数。


var next_win = 0;

var win = window。 open(","","");

function nextWin(){

if(next_win< urls.length){

win.onload = nextWin;

win.location.href = urls [next_win ++];

}

}


这是正确的行为吗?


-

-Mike

解决方案

be**@nospam.inva lid写道:

我正在尝试使用onload事件加载一系列网址。


这就是弹出窗口拦截器和浏览器猛烈攻击的最佳状态

内置弹出窗口阻止器。

我找到了什么是onload函数只调用一次
无论数组有多大。


不,它不是被叫,你每次都要重置它。

这是onload函数。
var next_win = 0;
var win = window.open("","","");
function nextWin(){
if (next_win< urls.length){
win.onload = nextWin;
win.location.href = urls [next_win ++];
}
}




对于你写它的方式,是的,它是正确的。如果你想重复调用一个函数
,那么显式调用该函数。但是你用它写的方式,如果它*反复调用它,它会在

无限循环中直到它杀死浏览器。


-

兰迪

comp.lang.javascript常见问题 - http://jibbering.com/faq


Randy Webb< Hi ******* *****@aol.com>写道:

be ** @ nospam.invalid写道:


我找到了什么是onload函数只调用一次
无论数组有多大。



不,它不是被调用,你每次都要重置它。




我想我不清楚。首先,我从主页

页面调用nextWin函数。 nextWin将子窗口的onload事件处理程序设置为

指向父窗口的newtWin函数,并将一个新的url加载到子窗口的

中。完成加载后,将按预期调用父级的nextWin函数

。它继续从数组加载下一个url。

完成第二个url的加载后onload事件处理程序

nextWin函数未被调用。

这是onload函数。

var next_win = 0;
var win = window.open("" ,",""");
函数nextWin(){
if(next_win< urls.length){
win.onload = nextWin;
win .location.href = urls [next_win ++];
}

这是正确的行为吗?



对于你的方式它写的,是的,它是正确的。如果你想重复调用一个函数,那么显式调用该函数。但是你写的方式,如果它*反复调用它,它将会无限循环,直到它杀死浏览器。



你似乎相信win.onload = nextWin这一行。调用nextWin

函数。我相信它只是设置了onload事件处理程序。


-

谢谢,

Mike


be**@nospam.inva 盖说:

nextWin将子窗口的onload事件处理程序设置为指向父窗口nextWin函数,并将新URL加载到子窗口中。



当您将新URL加载到窗口中时,清除任何现有的onload

处理程序以及任何其他脚本。


I''m trying to use the onload event to load a series of urls.
What I find is that the onload function is only called one time
no matter how large the array.
Here is the onload function.

var next_win = 0;
var win = window.open("", "", "");
function nextWin() {
if (next_win < urls.length) {
win.onload = nextWin;
win.location.href=urls[next_win++];
}
}

Is this correct behavior?

--
-Mike

解决方案

be**@nospam.invalid wrote:

I''m trying to use the onload event to load a series of urls.
Thats fallible at best with the onslaught of popup blockers and browsers
with built-in popup blockers.
What I find is that the onload function is only called one time
no matter how large the array.
No, it is not "called", you are resetting it each time.
Here is the onload function. var next_win = 0;
var win = window.open("", "", "");
function nextWin() {
if (next_win < urls.length) {
win.onload = nextWin;
win.location.href=urls[next_win++];
}
}

Is this correct behavior?



For the way you have it written, yes its correct. If you want to
repeatedly call a function, then explicitly call the function. But the
way you have it written, if it *did* call it repeatedly, it would be in
an endless loop until it kills the browser.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq


Randy Webb <Hi************@aol.com> wrote:

be**@nospam.invalid wrote:


What I find is that the onload function is only called one time
no matter how large the array.



No, it is not "called", you are resetting it each time.



I guess I wasn''t clear. First I call the nextWin function from the mainline
of the page. nextWin sets the onload event handler of the child window to
point at the parent''s windows newtWin function and loads a new url into
the child window. Upon completion of the load the parent''s nextWin function
is called as expected. It proceeds to load the next url from the array.
Upon completion of the loading of the second url the onload event handler
nextWin function is not called.

Here is the onload function.

var next_win = 0;
var win = window.open("", "", "");
function nextWin() {
if (next_win < urls.length) {
win.onload = nextWin;
win.location.href=urls[next_win++];
}
}

Is this correct behavior?



For the way you have it written, yes its correct. If you want to
repeatedly call a function, then explicitly call the function. But the
way you have it written, if it *did* call it repeatedly, it would be in
an endless loop until it kills the browser.


You seem to believe that the line "win.onload = nextWin" calls the nextWin
function. I believe it just sets the onload event handler.

--
Thanks,
Mike


be**@nospam.invalid said:

nextWin sets the onload event handler of the child window to
point at the parent''s windows nextWin function and loads a new url into
the child window.



When you load a new URL into a window, you clear any existing onload
handler, along with any other script.


这篇关于location.href和onload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆