HTMLViewer.ExecuteJavaScript Desktop-Web Differences

Could somebody be so kind and explain me the diffferences between an ExecuteJavaScript in a Desktop and in a Web Project?

Sub Action() HTMLViewer1.LoadURL("http://www.wikipedia.org/") End Sub

Sub Action() Dim jsSrc As String jsSrc = "document.forms[0].elements['search'].value=""xojo"";" HTMLViewer1.ExecuteJavaScript(jsSrc) End Sub

(I’m using: Xojo2014 r1.1 and Xojo2014 r2b4 on Mac with Safari)

Desktop: works properly

Web ERROR: Could not execute returned javascript: ‘undefined’ is not an object (evaluating ‘document.forms[0].elements[‘search’].value=“xojo”’)
Source: document.forms[0].elements[‘search’].value=“xojo”;

Thank you very much!

When/how do you fire the Javascript?

Thank you for your reply!
With two Buttons:
First for open the URL:
HTMLViewer1.URL = “http://www.wikipedia.org/
Second for write into a search field:
Dim jsSrc As String
jsSrc = “document.forms[0].elements[‘search’].value=”“xojo”";"
HTMLViewer1.ExecuteJavaScript(jsSrc)
And al last for click Enter:
Dim jsSrc As String
jsSrc = “document.getElementById(‘submit’).click();”
HTMLViewer1.ExecuteJavaScript(jsSrc)
Thank you for any help

Download sample: WebHTMLViewer-ExecuteJavaScript.zip

I could be wrong but you might be running into a security block.

  • with a desktop app you are basically building a browser that is loading a web page (from wikipedia). In browser security models, you (as the browser) have the right to execute Javascript in the web page as well as access the DOM for the web page itself.

  • with a web app, you are creating an iFrame for wikipedia inside an existing web page (your app). Communicating between frames that come from different domains on a single web page is a big security risk and may be blocked for certain actions. Accessing the DOM directly is usually not possible.

Research cross site scripting vulnerabilities (XSS) for tons of information about the risks and the security blocks.

You can set the URL of an iFrame - which allows you to load its contents - and there are limited other things you can do, but it can be a complicated affair.

Unless I don’t understand your problem… then never mind!

quote=102231:@Steve Upton
Research cross site scripting vulnerabilities (XSS) for tons of information about the risks and the security blocks.

(…)[/quote]
Thats it.
Cross site scripting is restricted in that case. Isn’t there a possible PHP-request u can perform? like ?=search"xojo"