javascript - HTML/JS: Calling a value from an object constructed onload in <body> -
i'm making website, , i'm creating "manager" object onload in body:
body id="real-world" onload="createarsim('ar-world','real-world','phone');"> createarsim(...) returns object bunch of things in useful. 1 such thing a
var pageindex which monitors current page.
i want display page number somewhere in web page. putting code inline, this:
<script> onload.pageindex.tostring(); </script> the issue throws error:
typeerror: onload.pageindex undefined and i'm not sure it. js code in constructor runs fine, can't find way access returned object 1 time i've finished running constructor.
edit:
ok, think might know why it's not working. first, need utilize document.onload phone call onload object i've returned. bigger issue how onload works -- can't phone call element of onload inline, because constructor isn't executed yet when run inline javascript code (it calls after has loaded...).
so can't set inline. i'll have clever editing javascript div i'm putting in directly, think.
you can next solve problem
window.onload = function() { var pageindex = createarsim('ar-world','real-world','phone').pageindex; var textnode = document.createelement('text'); textnode.textcontent = pageindex; document.body.appendchild(textnode); } this appends pageindex body.
javascript html oop onload
No comments:
Post a Comment