I have a test WebApp (not desktop that I can do!) with a WebHTMLViewer that points to a URL on my web site (http://www.webappdevelopments.com/textarea.html). It contains the following HTML (a form with a TextArea):
[code]
TextArea Test
[/code]
How can I place some text into this TextArea or retrieve the text from the TextArea?
Adding text
I have tried myHTMLViewer.ExecuteJavaScript(“formtest.editor1.setData(’” + myTextArea.Text + “’”) but it gives a JavaScript error in the browser
Retrieving text
I have no idea at all on how to retrieve the TextArea text since I cannot return a value from an ExecuteJavaScript( ).
I have set up a sample Xojo WebApp for testing if you’d like to give it a try. I am happy to change the web HTML file or drop up your version if needed.
I have tried dozens of combinations of getElementById and getElementsByTagName with the form name and TextArea name, but all give errors. I can change values on the WebPage using ExecuteJavaScript( ), but not on the WebHTMLViewer.
In terms of retrieval, I’m having trouble getting an alert( ) to display the contents of the TextArea too.
Is it possible to open an HTTPSocket into your own WebHTMLViewer?!
Are you using this ExecuteJavascript in the Shown event of the WebHTMLViewer? If the page within the iFrame hasn’t loaded yet you won’t be able to get the contentDocument.body object, and it could result in the undefined is not an object error you are seeing.
No, I am running the WebApp in the IDE. Why, should that matter?
I am running the ExecuteJavascript( ) when I click on a button, so everything should be fully loaded, certainly the web page is viewing in the WebHTMLViewer OK and I am using this to verify if the ExecuteJavascript() is working. It looks like this, where the text area and buttons above are in the WebApp and the WebHTMLViewer is below this with it’s TextArea visible, surrounded with a grey border:
I have tried dozens of combinations of getElementById and getElementsByTagName with the form name and TextArea name, but all give errors. I can change values on the WebPage using ExecuteJavaScript( ), but not on the WebHTMLViewer.
In terms of retrieval, I’m having trouble getting an alert( ) to display the contents of the TextArea too.
Is it possible to open an HTTPSocket into your own WebHTMLViewer?![/quote]
You don’t understand. Your HTML is at iFrame.contentDocument. You must modify your JavaScript to take that into account in locating the TextArea.
May I recommend you use the browser developer tools to see the elements involved.
All I want is a WebApp where I can display a standard WebHTMLViewer, insert some text into certain text fields, allow users to change the field data, then retrieve the text that they entered in.
I can tell the ExecuteJavaScript to find the document.getElementById( ) of the WebHTMLViewer, but seem unable to look inside it (e.g. to get/set the texture text) or even set it’s characteristics (e.g. give it a red background). It may be that I need to run the WebApp on the same domain as the HTML, but the JavaScript errors seem to indicate I am not referring to the objects properly, thus my call for help!
I used the .contentDocument.body because the web link suggested this was the way to manipulate an iFrame element.
You don’t download. You cannot do what you posted because the app does not make the disk space available to the Internet from a standalone app.
Create a WebFile, do not set it’s force download, and use its URL.
From the example of Open :
Dim f As FolderItem = GetFolderItem("MyFile.html") // Get the file using a FolderItem
If f <> Nil And f.Exists Then
// Convert the FolderItem to a WebFile
App.MyFile = WebFile.Open(f) // MyFile is a property on the App object
HTMLViewer1.URL = App.MyFile.URL
End If
What you want CAN be done but it’s not as simple as it seems. Browsers restrict this behavior specifically to prevent certain kinds of attacks and behaviors. For example you would not want a web app to masquerade as your bank website but secretly contain an iframe to your actual bank, capture your username/password and then fill them in on the iframe and wreck havoc on your accounts. To prevent this the browser does not permit one web site from seeing the data of another website across domains.
To SET the text in the HTML page the HTML page must create a function that sets the values necessary and then have an event listener to listen for events. You then pass a message to it with the javascript you want executed or the values of the text you want set depending on how you design your functions/listener.
To GET the text in the HTML page you want to add an event listener to your Xojo web app. You then want to use the event listener from above to send a message to the iframe HTML webpage to send a message back to the Xojo web app with the contents of the textfield.
To clarify (because I almost just freaked the fuck out) the document within the iFrame must be listening for your messages. So if you do not control the content of the iFrame, you still cannot control the page. Huuuge relief there.
So if this is just a test, to get the basics of manipulating another page in a HTMLViewer/iFrame, keep in mind that if you are not in control of the page within the iFrame that this will not work.
In the long run, it would be simpler just to include the HTML as a WebFile as Michel suggested. The web app would then be self contained, and you wouldn’t have to set up the listeners on the inner page.