I am coming from Java and try to learn Javascript right now. Doing that I have a problem to understand some behaviour I wrote.
I like to have two windows. caller.html opens called.html and invokes a function called printMe().
This is my code for caller.html:
<html>
<head>
<title> PDSA #4.1 : Page 1 - Communication between Windows </title>
</head>
<body>
<script>
fenster = open("called.html");
fenster.printMe();
</script>
</body>
and this is called.html:
<html>
<head>
<title> PDSA #4.1 : Page 2 - Communication between Windows </title>
<script>
function printMe() {
ausgabe = document.getElementById("toChange");
ausgabe.innerHTML += "Changed!";
}
</script>
</head>
<body>
<div id="toChange"></div>
</body>
Nothing happens when called.html is opened and from The Javascript Console in Chrome I can see the following error:
Uncaught TypeError: Object [object DOMWindow] has no method 'printMe'
(anonymous function)
Newbish as I am I don’t get it – why is printMe not found? The function is there and I see it in the code. Can you point me to the error?
Thanks in advance for any hints
André
if you use jquery, do it inside of, this would make your life easier..
or maybe this would work:
if it’s not working, you can call setTimeout before calling the function to make sure the child window done loading