ExternalEval() and document.write

Has anyone tried to do anything with ExternalEval and document.write to put stuff into Unity content embed pages?

End goal, we’re trying to write something like a javascript node/function into the hosting page from within Unity, but it doesn’t seem to work.

So I tried something even simpler, like this:

Application.ExternalEval("document.write('');");

The results are strange and inconsistent.

In Chrome, the page becomes blank, but view source shows the unmodfied page.

In Firefox, it blanks the page, and view source shows only .

IE continues to display an unresponsive page, but view source shows only , after which point IE displays a blank page.

In all cases, the address does not change.

It’s as if the ExternalEval is causing a brand new page to be written/loaded, instead of writing into the existing page, though the address doesn’t change.

Is there something obvious I’m missing here?

Whether it’s obvious or not is up for debate but I think that the main problem here is the scope in which that code is executed (“globally” for lack of a better term). If you want to write something into a specific area then I’d think that it’s best to use ExternalCall to call a specific browser-based JavaScript function that targets the specific area in which you want to insert some custom HTML (whether it sets a div’s innerHTML or whatever is up to you). Or at a minimum, get more precise with your ExternalEval call and target a specific div or region as opposed to issuing a page-global “document.write()” whose location seems to vary from browser to browser.

I suspected as much. Thanks Tom.