I have a app containing a WebView. When <!DOCTYPE html>
is not defined in a HTML page, it produces unexpected errors as snippets which I run are only compatible with HTML5.
So instead of writing <!DOCTYPE html>
everytime, can I simply set default quirk (quirk is a default HTML declaration which will be used if HTML version of a page is not specified).
So if page's HTML declaration is not specified, it will automatically render in HTML5.
Any ideas on how to do this? Major browsers use this technique (Including Chrome for Android).
EDIT
I have 500+ snippets like this using directly embedded SVG etc -
<svg width="300" height="200">
<polygon points="100,10 40,198 190,78 10,78 160,198"
style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" />
</svg>
These snippets don't run well on other versions of HTML. I don't actually have any problem in writing <!DOCTYPE html>
on every page but I am worried about my clients who can see, edit and modify my snippets or even create a new snippet.
I gave my app to my friends for testing and many of them complained the snippets that they created don't run properly and I think same sort of thing can happen with my clients as well.
Please help
EDIT: Chrome for Android does not use WebView [Source]:
Does this mean Chrome for Android is using the WebView?
No, Chrome for Android is separate from WebView. They're both based on the same code, including a common JavaScript engine and rendering engine.
So they have added this functionality on top of the normal WebView behavior. What you want to accomplish is not possible.
I think the only way this would be possible (based on my searches) is to override the WebView
behavior and do something like this instead:
HttpClient
to fetch the contents of the pageWebView.loadDataWithBaseURL
to render the HTML in the WebView
and specify the base url caught in step 1Obviously this is very hacky and I cannot confirm whether it works at all. So by far the best solution is to specify a <!DOCTYPE> tag on every page. If this requires validating snippets before loading / allowing clients to create them, then so be it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With