Google's JavaScript API makes use of the function document.write
, thus is not usable in XHTML.
Do you know a workaround how to get the custom search working in XHTML? Or is there a working alternative?
Google's JavaScript API makes use of the function document.write
, thus is not usable in XHTML.
Do you know a workaround how to get the custom search working in XHTML? Or is there a working alternative?
Copyright © 2021 Jogjafile Inc.
Are you actually serving your XHTML as XML (
application/xhtml+xml
)? If not, you don't have to worry about it, yet.document.write
will still work intext/html
mode though it is certainly poor practice in general.If you really are serving native XHTML... well, I suspect you may get more problems than just
document.write
, as there are a fair few things that can trip scripting up when it's not expecting to be run in XHTML. But you can hack it the problem by sabotagingdocument.write
.The simplest method would be something like:
however you would need more messing around if it tried to write
<script>
tags (since setting them throughinnerHTML
doesn't execute them; you would have to pick them out withgetElementsByTagName
and run each one manually), or partial bits of elements across different calls towrite
(in which case you'd have to collect strings and glue them together when it's finished).