|By: Paul S. Cilwa||Viewed: 7/23/2018
|Topics/Keywords: #Computers #DOM #HTML #Organica #Programming #VB.NET||Page Views: 148|
|How to build into Organica the ability to create pages to order from a script.|
Previously we created an HTML file that can be viewed in any browser window. Then, we designed a browser of our own for viewing it. But since the web page (currently) has no links, our browser can't do anything else.
What we want is to use the web page as a template, which can then be modified by the Organica browser as needed, before a page is ever shown.
There are primarily two ways of accomplishing this. The first is to load the page, then use methods of the WebBrowser control to modify sections as needed. The second is to read the HTML file, modify it, and load it directly into the control.
I find the first technique to be the simpler of the two. And the only modification we need to make to the current HTML is to add an ID attribute to the elements we'd like to modify.
While it isn't completely necessary to know an element's ID to access it programmatically, if you do know it, the task becomes much simpler.
Be aware, though that you cannot modify the document until after it's been completely loaded. The only truly reliable way to do this is to handle the WebBrowser control's DocumentCompleted event. Which, in point of fact, makes it the perfect place to put the modification code. Here's a quickie text example:
Private Sub Canvas_DocumentCompleted(sender As Object, _ e As WebBrowserDocumentCompletedEventArgs) Handles Canvas.DocumentCompleted Canvas.Document.GetElementById("organica_Banner").InnerHtml = _ "<img src='" & Myself.PhotoPath & "'>" & _ "<h1>" & Myself.Nickname & "</h1>" End Sub
Start the app. Now the banner, instead of displaying the words "welcome to Organica", you now get to read your username and see your picture.