Android Question B4a CSS injection into WebBrowser HTML document

Rusty

Well-Known Member
Licensed User
Longtime User
Is there a way to have a CSS file in assets or anywhere that is a text file containing CSS and "inject" it into an HTML document?

I.e. I have the CSS defined, but don't want to include it in every HTML file (for obvious reasons).
I'd like to open the HTML and then insert the CSS into it for display in the WebBrowser view.
Other than creating a string loading the html top from DOCUMENT... to...</title> and the appending the CSS file contents; then appending the rest of the HTML body... is there a way to do this?
Thanks,
Rusty
 

drgottjr

Expert
Licensed User
Longtime User
what you're doing is a wonderful - if low-tech - way of dynamically controlling your html page.
it gives you immense control over what you want loaded, and it allows for html updates on the fly
(not unlike updating an in-app database periodically). for example, i have a map app. as map
providers come and go and change their endpoints, my users can download new provider information
without having to download and install the app. if you divide your html (as you are already doing), you
can do hot fixes, as needed. or even modify css.

there is another way using javascript that essentially builds the page piece by piece, which is what you are
doing already. with a fair amount of effort, you could modify that approach so that you send a javascript
command to the webview and have the css script become part of the html. you would have to cause the
page to be reloaded, however, as i do not believe it is possible to alter css formatting after the page has
already been loaded.

i don't see the advantage of approaching it this way, based on the very happy results i have had creating
pages dynamically before loading in accordance with whatever css and code that i want to be in place
in a given situation. amazon, among others, have been very successful creating web pages on the fly.
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Thank you for your kind response. :)
It seems a bit unsophisticated the way I'm doing it now, so I was thinking there might be a better way.
I saw that in B4j there is a way, but it appears to be a different base.
Rusty
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
Upvote 0
Top