Function inside onload function undefined?

I have a web page with a javascript function inside window.onload that is not initialized ("undefined is not a function"), and I don't know why.

My code looks like this:

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

In almost all browsers, this works fine, but in some (the default Android browser and Dolphin) I get the following when I onloadtry to execute loadthis(88,frm):

Uncaught TypeError: undefined is not a function

I tried to define a function myonload()and call it from a tag bodywith the same behavior.

A page with full js code inside this .

EDIT # 1 There seems to be some inconsistencies in the browsers JS browser. For example, this code:

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

gives this result:

############## 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);
   }
 }
}
+4
1

.endsWith(), undefined frame, frame.remove() ( , iframe).

0

Source: https://habr.com/ru/post/1661764/


All Articles