Just wanted to add that I experimented out a little with using an
iFrame (it finds the Javascript, but there's a huge problem with the
scope). I want any JS functions between Outer document and inner
container (dynamically added) to be flexible to call each other (like
how its behaving on a DIV). I am back to square one - Need something
approach like the DIV container where the JS would be accessible (like
how its working on the IE).

Uploaded the modified version on http://pastebin.com/MhTkdhFQ

/////////////////////////////////////////////////////////////////////////////////////////////////////////
<html>
        <head>
                <script>
                        /* the input type = hidden is necessary or the JS won't 
be
accessible */
                        /* script defer tag is also necessary */
                        function insertHTMLOnButtonPress() {
                        try {
                                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>";
                                var x = document.getElementById('test');
                                var y=(x.contentWindow || x.contentDocument);
                                if (y.document)y=y.document;

                                y.write(s);
                                } catch(ex) {
                                        alert(ex.name);
                                }
                        }
                </script>
        </head>
        <body>
                **********************************<br/>
                <!-- Don't close the div inline, causes some problem and 
replaces
the buttons too -->
                <iframe id="test" name="test">hello world</iframe>
                **********************************<br/>
                <input type="button" onClick="insertHTMLOnButtonPress();"
value="Insert some dynamic html"/>
                <input type="button" onClick="dynamicallyInsertedFunction();"
value="Call Dynamically Inserted Method"/>
        </body>
</html>
/////////////////////////////////////////////////////////////////////////////////////////////////////////

On Oct 1, 2:14 pm, Swaroop <[email protected]> wrote:
> 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 
> tohttp://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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to