0

Every time my page gets loaded I want some javascript to get executed if a new message is in the TempData.

window.onload = function () {  
      $.jGrowl('Hello world!');
};

And that works fine. But do I have to put the call inside a windows.onload or other eventhandlers, because if I do it like this

<script type="text/javascript>
$.jGrowl('Hello world!');
</script>

it won´t work It comes up with a

SCRIPT438: Object doesn't support this property or method

I have been trying to put the javascript in the bottom of the page to make sure averything else is loaded first

Hope for some help Jakob

Jakobbbb
  • 515
  • 1
  • 4
  • 10

2 Answers2

1

https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onload

The problem is the code fires before the DOM has loaded.

Here's a related article.. window.onload vs document.onload

Community
  • 1
  • 1
0

According to their example this should be working perfectly... I tried to unwrap the call, the best I could do is remove the outter self executing function...

<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jquery-jgrowl/1.2.12/jquery.jgrowl.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-jgrowl/1.2.12/jquery.jgrowl.min.js"></script>
<script type="text/javascript">
$(function(){
    $.jGrowl("Hello world!");
});
</script>

My guess is the library uses dom ready so its not available to jquery until after dom ready has executed.

Here is a JSBIN

Shanimal
  • 11,517
  • 7
  • 63
  • 76
  • 1
    Ok I found out what was the problem. It did´nt load the the jgrowl library. Why it worked in the onload i have no idea about. But its working now. Thanks for all the replies – Jakobbbb Jun 23 '14 at 18:15