Allow JavaScript in Desktop HTMLViewer

How do I allow JavaScript in desktop HTMLViewer?

This is a dynamic HTMLViewer that does not have one set link.



The world is round so that many users now sleep. Your question was rather vague. What are you trying to? Which platform? iOS, Desktop or Web? What have you tried?

Javascript works in a HTMLViewer… Unless the code is broken.


Put this code in a HTMLViewer Opening() event, for example:

Const someHtml = "<!DOCTYPE html><html><head></head><div></div><script> "+_
"const ul = document.createElement(""ul""); const li = document.createElement(""li""); "+_
"const textnode = document.createTextNode(""← Inserted using JS""); li.appendChild(textnode); "+_
"ul.appendChild(li); document.body.appendChild(ul);</script></html>"

Var temp As FolderItem = SpecialFolder.Temporary.TemporaryFile
Var htmlFileIncludingJS As FolderItem = SpecialFolder.Temporary.Child(temp.Name+".html")
temp.MoveTo(htmlFileIncludingJS) // needs to be html type

Var fileToWrite As TextOutputStream = TextOutputStream.Open(htmlFileIncludingJS)


Desktop, I thought I mentioned that.

Yes, but I don’t have a single HTML code, the user inputs a url and the HTMLViewer shows that

I see, but does this support JavaScript?

If the loaded HTML contains safe code, sure. The HTML code I posted above contains JS and runs it.

Avoid the unsafe http: protocol, use https: to avoid security problems.

Got it

Also, how would I change all link targets from _blank to _parent?

Find and Replace

Didn’t I explain that the user inputs a URL. I want to change the code in the website so that link targets go to “_parent”.

I think that such need demands lots of “magical thinking”, design and trials, if possible at all. Can’t answer.

You could work up some javascript that, when executed, would modify the DOM. Once the URL download is complete, then you can tell the Viewer to execute that javascript. AFAIK, that javascript does not have to be in teh webpage that was downloaded.

Alternatively, you could download the source of the webpage the user wants to display, use find/replace to modify it, then load it into the Viewer.

How feasible these approaches are in terms of not being stopped by some security or other issue, I know not.

If the HTML page is on your site, you can do what you describe in JavaScript, if you have enough knowledge to write the necessary program.

If the page is on another site, chances are security may not permit what you are after.

Is there a way to just open _parent links in the same HTML Viewer

Sure, just implement the CancelLoad event and do whatever you want.

So far, it is unclear what you want to achieve. Are you trying to modify an HTML page from another site, or your own ?