Single-Page Applications (SPAs). "Most major modern platforms like Gmail, Google Maps, Trello, Netflix, and Airbnb are built as SPAs."
All HTML tags that might be used must have a unique ID.
You use Fake URLs to send messages to FreeBASIC using JavaScript or wrap the button or text in a Fake URLs.
FreeBASIC code intercepts navigation attempts and cancels and handles the message.
Use JavaScript innerText or innerHTML to Get/Set text or HTML.
You can change any element including the whole page. One page can be a thousand pages.
No point in me trying to explain it, run this query in Google AI search mode in a browser.
"Using FreeBASIC and the Afx library by José Roca, I want to build a local one-page browser application. Data is passed to FreeBASIC code in fake URLs that are really messages. Data is passed from FreeBASIC code to the browser using a javascript call to replace inner text or inner html to change the html in the browser. Thus, the page can change, or other things can happen using fake URL messages. How would I go about doing this?"
You can ask further questions for more information. Include "using FreeBASIC and José Roca's Afx library" or it might get sidetracked.
I haven't tried this yet, but I know it will work because I did it with PB. I'm not up to speed on FreeBASIC. I have other code I'm focused on, but it did this query to make sure I could build an easy application before I committed to FreeBASIC. Thanks to José I know I can do it when the need arises because I did it on PB using his code.
If anybody more adapt with FreeBASIC does give it a try, it would be interesting to know how it works for you. Lot of powerful tools you can use inside the browser. José's code provides a direct bridge to FreeBASIC.
Happy trails...
Hi Stan,
You may want to consider using WebView2 instead of the legacy WebBrowser control before you invest too much time into this approach.
The WebBrowser control is based on Internet Explorer and is already obsolete, with many limitations regarding modern HTML, CSS, JavaScript and communication between the host application and the embedded page.
In contrast, my CWebView2 class provides a clean and modern wrapper around Microsoft's WebView2 (Chromium-based) and gives you:
- full modern HTML/CSS/JS support
- reliable two‑way communication between JavaScript and FreeBASIC
- the ability to execute JavaScript directly from your code
- no need for "fake URLs" or navigation hacks
- much better performance and long‑term support
If you plan to build SPA‑style interfaces or dynamic HTML‑driven UIs, WebView2 is a far better foundation and will save you a lot of work in the long run.
Just a friendly suggestion before you go too deep into something that is already outdated.
CWebView2 class: https://github.com/JoseRoca/AfxNova/blob/main/AfxNova/CWebView2.inc
A few examples: https://github.com/JoseRoca/AfxNova/tree/main/Examples/WebView2
Documentation: https://github.com/JoseRoca/AfxNova/tree/main/docs/WebView
BTW the old WebBrowser control is also available in my AfxNova framework for FreeBasic.
CWebCtx: https://github.com/JoseRoca/AfxNova/blob/main/AfxNova/CWebCtx.inc
CWebBrowserEvents: https://github.com/JoseRoca/AfxNova/blob/main/AfxNova/CWebBrowserEvents.inc