ID:2845192
 
Not a bug
BYOND Version:514
Operating System:Windows 10 Home 64-bit
Web Browser:Firefox 108.0
Applies to:DM Language
Status: Not a bug

This is not a bug. It may be an incorrect use of syntax or a limitation in the software. For further discussion on the matter, please consult the BYOND forums.
Descriptive Problem Summary:

The reference states that the output() proc is able to call javascript functions using the format:

    usr << output("[params]", "[element]:[function]")


When testing this in the default BYOND skin, it does function properly. When you create your own skin, however, it fails. I thought, perhaps, it was failing only in cloned browser elements, but it seems to fail no matter what, unless you use the default skin.

Numbered Steps to Reproduce Problem:

Create a new environment, paste the code below (from the ref example), and run. Use the newtext verb to replace the text in the browser.

You will see the expected result.

Now, create a new DMF interface file with a window containing a default browser element named browser. Run the program again. Use the newtext verb and notice the expected result fails to occur. The text is not changed.

Code Snippet (if applicable) to Reproduce Problem:
mob/Login()
. = ..()
usr << browse(" ")
usr << output(\
{"
<script type="text/javascript">
function replace(v) {
document.getElementById('foo').innerHTML =
v.replace(/&/g, '&amp;').replace(/</g, '&lt;');
}
</script>
<div id="foo">This text can change.</div>
<p>And this can't.</p>
"}
,
":browser");

#define LP(str) list2params(list(str))
mob/verb/newtext(T as text)
usr << output(LP(T), ":browser:replace")


Expected Results:

As the reference indicates, it is expected that the javascript function would be called in any browser element a user creates in their DMF interface file.

Actual Results:

The output() only functions properly for the default BYOND skin's browser element, and fails in any user-created browser elements.

Does the problem occur:
Every time? Or how often? Everytime
In other games? Yes
In other user accounts? Not sure
On other computers? Don't know.

When does the problem NOT occur?

If you only use the default BYOND skin, then the javascript function is called.

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.)

I presume this has been broken since 4.0, when interfaces were introduced.

Workarounds:

None.
You may be relying on javascript behavior that IE7 doesn't support, you'll want to force it into edge mode which will use the IE version the user has installed, up to IE11.
<META http-equiv="X-UA-Compatible" content="IE=edge">


In your head section.

This feature absolutely works, Eternia and SS13 both rely on it heavily, very heavily.

You're also making the rookie mistake of usr in Login(), but in this case it's not gonna make a difference; in a real hosted world though it absolutely can.
I made no usr in login mistake here. That's code in the reference. Like I said, it works in the default skin. It does not work in a 4.0 browser element.
The exact code in the reference is working fine in my test environment, which has a skin with nothing but a window with a browser element.



I'll bug Lummox to un-usr-abuse the reference entry though. Your issue seems to be something on your end.
Now that's frelling weird. I built a test world before making this post, and it did not work then. I've changed absolutely nothing, just loaded up the test world and it's working. o_0 I'll fiddle with my code in the project and see what's up there. I think it may be that the browser isn't set to default in the dmf, though I do winset() it to default before sending the script. Whether or not it's actually default is a question I need to answer, and also see how this works in the test world with a cloned window, which is what my project uses. If I can get this working, it'll mean a lot for the chat. The output window is lacking in that it doesn't animate gifs, and I want to add Tenor gifs to the chat.

That meta option above may fix an issue Koz was having with showcode. Good to know. Thanks!
Okay. Just tested with a cloned browser element. It works with a cloned browser. That eliminates the possibility of this being a BYOND bug. The issue is in my code, somewhere. You can close this.
Spevacus resolved issue (Not a bug)
For those wondering, the issue was that the javascript function definition and call to that function were sent too close together so that the function was not registered by the time the call was made. Not sure why IE didn't give me a script error. I put a tick delay between the two output()s and it works as expected.