# HTMLViewer.ExecuteJavaScript Desktop-Web Differences

**URL:** <https://forum.xojo.com/t/htmlviewer-executejavascript-desktop-web-differences/17380>\
**Category:** Web\
**Created:** [June 19, 2014, 9:34am UTC](https://forum.xojo.com/t/htmlviewer-executejavascript-desktop-web-differences/17380 "2014-06-19T09:34:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Calvi\_Tecnologie\_srl\_Calvi\_And](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/ba8739/32.png) [@Calvi\_Tecnologie\_srl\_Calvi\_And](https://forum.xojo.com/u/Calvi_Tecnologie_srl_Calvi_And)\
**Post date:** [June 19, 2014, 9:34am UTC](https://forum.xojo.com/t/htmlviewer-executejavascript-desktop-web-differences/17380/1 "2014-06-19T09:34:29Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Jan-Ole\_Berger](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@Jan-Ole\_Berger](https://forum.xojo.com/u/Jan-Ole_Berger)\
**Post date:** [June 19, 2014, 2:35pm UTC](https://forum.xojo.com/t/htmlviewer-executejavascript-desktop-web-differences/17380/2 "2014-06-19T14:35:14Z")

</div>

When/how do you fire the Javascript?

---

<div class="post-metadata">

**Author:** ![Calvi\_Tecnologie\_srl\_Calvi\_And](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/ba8739/32.png) [@Calvi\_Tecnologie\_srl\_Calvi\_And](https://forum.xojo.com/u/Calvi_Tecnologie_srl_Calvi_And)\
**Post date:** [June 19, 2014, 3:37pm UTC](https://forum.xojo.com/t/htmlviewer-executejavascript-desktop-web-differences/17380/3 "2014-06-19T15:37:04Z")

</div>

Thank you for your reply!  
With two Buttons:  
First for open the URL:  
HTMLViewer1.URL = “[http://www.wikipedia.org/](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](https://dl.dropboxusercontent.com/u/20486939/WebHTMLViewer-ExecuteJavaScript.zip)

---

<div class="post-metadata">

**Author:** ![Steve\_Upton](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/6de8d8/32.png) [@Steve\_Upton](https://forum.xojo.com/u/Steve_Upton)\
**Post date:** [June 19, 2014, 7:52pm UTC](https://forum.xojo.com/t/htmlviewer-executejavascript-desktop-web-differences/17380/4 "2014-06-19T19:52:29Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Jan-Ole\_Berger](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@Jan-Ole\_Berger](https://forum.xojo.com/u/Jan-Ole_Berger)\
**Post date:** [June 20, 2014, 7:45am UTC](https://forum.xojo.com/t/htmlviewer-executejavascript-desktop-web-differences/17380/5 "2014-06-20T07:45:43Z")

</div>

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"`

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:16pm UTC](https://forum.xojo.com/t/htmlviewer-executejavascript-desktop-web-differences/17380/6 "2020-10-29T17:16:48Z")

</div>


