Hi Android experts,

I have a weird code situation where I need to have a <DIV> to hold
dynamic HTML generated. Here I am populating the <DIV> using its
innerHTML attribute and it works fine and dynamically adds any HTML
elements that are there in the dynamic HTML.

The problem I am facing now is if the dynamic (generated else where)
HTML contains a list of Javascript methods, these methods aren't
accessible to be callable from the buttons inside the div or outside
the div (

I was able to get the requirement working in Desktop Internet Explorer
7+. This however doesn't work on Firefox too . I understand this isn't
the best way, but to use addChild etc is, but then I would have to
manually parse my HTML myself and construct all the child elements i.e
do all that the innerHTML will do eventually (logically, i mean).

////////////////////////////////////////////Code also uploaded to
http://pastebin.com/Q6w5hRPG ////////////////////////////
////////////////////////////////////////////Code works on Internet
Explorer 7+//////////////////////////////////////////////////////
<html>
        <head>
                <script>
                        /* the input type = hidden is necessary or the JS won't 
be
accessible */
                        /* script defer tag is also necessary */
                        function insertHTMLOnButtonPress() {
                                var s = "<html><input type='hidden' 
id='dummyHidden'/
><head><script defer='defer'>function dynamicallyInsertedFunction()
{ alert('Successfully called - dynamicallyInsertedFunction'); } </sc"
+ "ript></head><body><input type='text' value='Hello World'/><input
type='button' onClick='dynamicallyInsertedFunction();' value='Call
Dynamically Inserted Method'/></body></html>";
                                /* Clearing out innerHTML is also required to 
flush the innerHTML
so that repeated attempts - i.e new HTML/JS should work */
                                document.getElementById('tempBody').innerHTML = 
'';
                                document.getElementById('tempBody').innerHTML = 
s;
                        }
                </script>
        </head>
        <body>
                **********************************<br/>
                <!-- Don't close the div inline, causes some problem and 
replaces
the buttons too -->
                <div id="tempBody"></div>
                **********************************<br/>
                <input type="button" onClick="insertHTMLOnButtonPress();"
value="Insert some dynamic html"/>
                <input type="button" onClick="dynamicallyInsertedFunction();"
value="Call Dynamically Inserted Method"/>
        </body>
</html>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Also posted on WebDeveloper.com - 
http://www.webdeveloper.com/forum/showpost.php?p=1116504

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to