ID:104862
 
Resolved
Applies to:DM Language
Status: Resolved (480)

This issue has been resolved.
Essentially what the title says. I can't guess with any real degree of accuracy as to how difficult this is (though if the browse() windows work like in-interface browser controls...), but the gist of it is summed up like this:

I click a link in a browse() window, and instead of the whole window flashing / losing entered data / having the scroll reset, a custom javascript function is called (one that is already on the page, as in the /proc/Output() example) and textual data is passed to it as parameters. From there, in this specific example, I take two params (object ID and new innerText) and use those to update an element on the page without disrupting anything else or the document's scroll position.

client/New()
. = ..()
src << browse({"
<html>
<head>
<title>
test
</title>
<script type="text/javascript">
function ReplaceText(ID, NewText) {
alert("check");
document.getElementById(ID).innerText = NewText;
}
</script>
</head>
<body>
<p id="testelement">Testing...</p>
<a href="?a=test">test</a>
<input type="text" value="This doesn't get overwritten!"></input>
</body>
</html>"}
, "window=wtest")

client/Topic(href,href_list[],hsrc)
var/list/T = list( )
T["ID"] = "testelement"
T["NewText"] += "IT WORKED"
usr << output(list2params(T),"wtest:ReplaceText")


In this case, "wtest:ReplaceText" resolves to the window created by browse() (and a specific function therein) and not a control in the interface. The idea behind this is to allow a sort of pseudo-AJAX in browse windows by having Dream Daemon "push" updates to the clients (in the form of javascript calls) instead of having the browse windows "pull" through the (unsupported anyways) XmlHTTPRequest object.
Running the code in the request verbatim on a fresh environment causes nothing to happen when I hit the "test" link as of Byond 476.1086. Also, confirmed the javascript itself works when the page is stored in an HTML file and called via javascript:... in the address bar
I really would appreciate even just someone acknowledging this idea...
Bump.
Seems like the request boils down to allowing windows created through browse() to retain an ID in the interface to be used later (so that the javascript output() will work). In other words, you want the "window" parameter to be the same thing as an interface window parameter. That should be do-able (and I'm surprised we overlooked it.. I'll have to test as this stuff is a bit fuzzy).

I think you can replicate this by avoiding browse() and creating your own dummy browser window in the dmf, using winclone() to make copies as needed. Then you'll have legitimate interface IDs to pass to the output.

I'll take a look. We are way behind on software developments with the new site foo but are at least trying to survey the requests and bugs to see what is workable in the next release (480). We're trying to get that out in the next few weeks.
If you use browse() to open a popup using the old syntax, the popup name becomes the name of the window and the browser in it is [window].browser. So in your example you can send output to "wtest.browser:ReplaceText". I've made a note in the reference.