ID:88547
 
BYOND Version:461
Operating System:Windows 7 Ultimate
Web Browser:Chrome 3.0.195.38
Status: Deferred

This issue may be low priority or very difficult to fix, and has been put on the back burner for the time being.
Descriptive Problem Summary:
Calling/sending params to a javascript function via output() does not work... see the code snippet + output entry for more information.

Numbered Steps to Reproduce Problem:
Tried using the snippet in the DM reference with no results

Code Snippet (if applicable) to Reproduce Problem:
        Click()
winset(usr, "child", "left=browin") // browin contains the browser element named 'browser'
usr << output(\

{"
<script type="text/javascript">
function replace(v) {
document.getElementById('foo').innerHTML = v;
}
</script>

<div id="foo">This text can change.</div>
<p>And this can't.</p>
"}
,
"browser");

usr << output("'Hi'","browser:replace")


Expected Results:
"This text can change" to be changed into "'Hi'".

Actual Results:
No changes happen at all.

Does the problem occur:
Every time? Or how often?
Everytime. N/A for the other questions.

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.)
Did not try yet.
I was able to verify the problem. Unfortunately this turns out to be a non-trivial issue to fix because what's happening is that you're calling the JavaScript function before the document is ready. There seems to be no simple means of telling if the browser is ready to accept JavaScript commands.

However because this is a timing issue, it should be easy enough to resolve with a sleep(). If you put a short sleep() in between sending the page to the browser and calling the function, the issue will go away. I tested with a 1-second delay and had no problem, but you could probably get away with an even shorter timeout. I recommend that as a workaround. Another possible workaround is to simply include the text you want to be there when you send the original document to the browser, and only use JS for later updates.
I see, thanks for the info!