jquery - $(window).load returns function not defined when called from external .js file -
i have main.js external file implemented:
function initialize() { ... }
and main.php file call:
<script type="text/javascript" src="./main.js"></script>
then call:
$(window).load(function() { initialize(); }
i know window.load fires code after loaded , ready.
why return referenceerror: initialize not defined
?
edit: here it's code in samplest form:
// # main.js.php file <?php session_start(); include_once("include/functions.php"); session_write_close(); ?> var elements = []; var element = { container: "", visible: false, init : function(div) { .... } }; function initialize() { elements.push(element.initialize("mydiv")); } // # main.php file <?php session_start(); include_once("include/functions.php"); include_once("include/db_engine.php"); session_write_close(); } ?> <?xml version="1.0" encoding="utf-8" ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"> <head> <meta http-equiv="content-type" content="text/html" /> <link rel="stylesheet" type="text/css" href="./css/stile.css" media="all" /> <script type="text/javascript" src="./js/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="./main.js.php"></script> <script type="text/javascript"> $(window).load(function() { initialize(); }); </script> </head> <body> <div id="mydiv"></div> </body> </html>
var elements = []; var element = { container: "", visible: false, init : function(div) { //... return 'hello world'; } }; function initialize() { elements.push(element.init("mydiv")); //was typing error }
your object definition , function initialize()
pushes ["hello world"]
elements
or function given, not entire var element= {...}
object.
and additional workout
$(window).load(function() { //initialize(); console.log('window call'); }); $(document).ready(function() { //initialize(); console.log('document call'); });
fires..
first: 'document call'
second: 'window call'
Comments
Post a Comment