I need to use document.write() in XSL. Will it work ? Please help

Recommended Answers

All 2 Replies

If you should use inside an XSL file a script with document.write() and you cannot edit it(some counter for example), the next trick can help:

<script type="text/javascript">
// this is your script somewhere in HEAD
                        var document_write = '';
                        var obj = null;
                        document.write = function(str) {
                            document_write += str;
                        }
                        function begin(id) {
                            obj = document.getElementById(id);
                        }
                        function end() {
                            if(obj) {
                                obj.innerHTML = document_write;
                            }
                            document_write = '';
                        }

</script>

<!-- somewhere in BODY where you plan use another's script -->
<div id="some_id">
     <script type="text/javascript">begin('some_id');</script>
     <script type="text/javascript" src="http://www.other-domain.com/some_script_with_document_write.js"></script>
     <script type="text/javascript">end();</script>

</div>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.