onload函数里面的函数未定义?

时间:2016-11-23 20:45:44

标签: javascript html

我在window.onload中有一个javascript函数的网页没有被初始化(" undefined不是函数"),我不知道为什么。

我的代码是这样的:

<script type="text/javascript">
 function loadthis(e,pg) {
    ...
 }
 window.onload = function() {
    loadthis(88,frm);
 }   
</script>

在几乎所有浏览器中,这都可以正常工作,但在某些(默认的Android浏览器和Dolphin)中,当onload尝试执行loadthis(88,frm)时,我会得到以下信息:

Uncaught TypeError: undefined is not a function

我尝试定义myonload()函数并使用相同的行为从body标记中调用它。

is this内包含完整js代码的页面。

编辑#1 浏览器的JS引擎似乎存在一些不一致之处。例如,此代码:

console.log("  ############## 1 ");
console.log("  ############## 2 "+frame);
console.log("  ############## 3 "+frame.src);
console.log("  ############## 4 "+frame.src.endsWith(pg));

给出了这个输出:

############## 1 
############## 2 [object HTMLIFrameElement]
############## 3 http://luis.impa.br/varios/framebackground.html
**Uncaught TypeError: undefined is not a function**

不知道这意味着什么。 frame.src已定义。似乎.endsWith在这些浏览器中不起作用。

EDIT2 :对于记录,这是loadthis的正文:

function loadthis(e,pg) { //{{{2
 clickbackground.trigger('click');
 jQuery("body").trigger("click");
 $('html').trigger('click');

 var evt = e || window.event;
 if (evt != 88 && evt !== "null") evt.preventDefault();
 if (evt.button == 1) {
   window.open(pg, '_blank');
 } else {
   //if (frame && frame.src && frame.src.endsWith(pg)) return;
   if (frame && frame.src && frame.src.match(pg) != null) return;
   if (evt !== 88) spinner.style.display = "block";
   if (frame && frame.src) {
    $.when($(frame).fadeOut(250)).promise().done(function() {
      //Comment for Dolphin
     frame.remove();
     frame.src = pg;
      //Comment for Dolphin
     container.append(frame);
     $(frame).fadeIn(600);
     });
   } else {
    if (!frame) frame = document.getElementById("MainFrame");
    $(frame).fadeOut(0);
    frame.src = pg;
    $(frame).fadeIn(600);
   }
 }
}

1 个答案:

答案 0 :(得分:0)

除了缺少else if (userInput == "stats") // Ignore the else { // Name is Allura. ID is stored too. Increments from 0 to work with the vector // What can I do to make a way of showing information only in that nth element (like element 0 if player id is 0) etc? } 函数的实现之外,当我发出.endsWith()命令时,浏览器将undefined设置为frame(我这样做是为了防止历史记录frame.remove())。