Daniel Pirone | 16 Mar 08:38
Picon

setting innerHTML failing occasionally ?

Howdy -

I have a phonegap ( recent git head version ) based iOS app that does
a lot of dynamic HTML generation  - mostly updating the innerHTML of
divs and spans  with content fetched from a remote server.

every couple of "interactions" , I will see a silent failure of  code
roughly of the form:

    document.getElementById("RestaurantLocationName").innerHTML =
theName;

Sometimes it will work, sometimes it doesn't ...  no obvious reasons
why - I can try a second later, and it works again ...

It happens in both the simulator and on real iPhones ...

Is it possible that somehow the DOM needs to be told to sync or
refresh or ... ?

Suggestions ?

Thanks in advance!

- djp

--

-- 
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phonegap@...
(Continue reading)

Shazron Abdullah | 16 Mar 08:54
Gravatar

Re: setting innerHTML failing occasionally ?

http://blog.johnmckerrell.com/2007/03/07/problems-with-safari-and-innerhtml/

It's been discussed on this list previously as well (do a search on this list to see).

On 2011-03-16, at 12:38 AM, Daniel Pirone wrote:

> Howdy -
> 
> I have a phonegap ( recent git head version ) based iOS app that does
> a lot of dynamic HTML generation  - mostly updating the innerHTML of
> divs and spans  with content fetched from a remote server.
> 
> every couple of "interactions" , I will see a silent failure of  code
> roughly of the form:
> 
>    document.getElementById("RestaurantLocationName").innerHTML =
> theName;
> 
> Sometimes it will work, sometimes it doesn't ...  no obvious reasons
> why - I can try a second later, and it works again ...
> 
> It happens in both the simulator and on real iPhones ...
> 
> Is it possible that somehow the DOM needs to be told to sync or
> refresh or ... ?
> 
> Suggestions ?
> 
> Thanks in advance!
> 
(Continue reading)

Jesse Macfadyen | 16 Mar 09:50
Gravatar

Re: setting innerHTML failing occasionally ?

For sanity sake, wrap your Dom manipulation code in a try catch and
report any exceptions. May not be the issue Shaz mentioned,  could be
bad markup too.

Cheers,
  Jesse

Sent from my iPhone

On 2011-03-16, at 1:00 AM, Shazron Abdullah
<shazron.abdullah@...> wrote:

> http://blog.johnmckerrell.com/2007/03/07/problems-with-safari-and-innerhtml/
>
> It's been discussed on this list previously as well (do a search on this list to see).
>
> On 2011-03-16, at 12:38 AM, Daniel Pirone wrote:
>
>> Howdy -
>>
>> I have a phonegap ( recent git head version ) based iOS app that does
>> a lot of dynamic HTML generation  - mostly updating the innerHTML of
>> divs and spans  with content fetched from a remote server.
>>
>> every couple of "interactions" , I will see a silent failure of  code
>> roughly of the form:
>>
>>   document.getElementById("RestaurantLocationName").innerHTML =
>> theName;
>>
(Continue reading)

friherd | 16 Mar 10:07
Favicon

Re: setting innerHTML failing occasionally ?

I can confirm that I see the same thing in my iOS app: for no apparent
reason setting the HTML of a DOM object in iOS sometimes simply does
not work. No errors are reported. Try/catch catches nothing. It simply
does not work.

I followed the suggestion in
http://www.google.com/url?sa=D&q=http://blog.johnmckerrell.com/2007/03/07/problems-with-safari-and-innerhtml/
and that works for me. Specifically, I check to see if the length of
the HTML in the DOM object is 0 after my insert. If it is I wait 250ms
and try again.

Actually, I do this in a loop and sometimes I notice in my console.log
files when my iPhone is connected to the Xcode console that it fails 3
or 4 times before being successful.

4ank

On 16 mar, 09:50, Jesse Macfadyen <jesse.macfad...@...> wrote:
> For sanity sake, wrap your Dom manipulation code in a try catch and
> report any exceptions. May not be the issue Shaz mentioned,  could be
> bad markup too.
>
> Cheers,
>   Jesse
>
> Sent from my iPhone
>
> On 2011-03-16, at 1:00 AM, Shazron Abdullah
<shazron.abdul...@...> wrote:
>
(Continue reading)

Mikko Ohtamaa | 16 Mar 22:08
Gravatar

Re: setting innerHTML failing occasionally ?


On Mar 16, 11:07 am, friherd <frih...@...> wrote:
> I can confirm that I see the same thing in my iOS app: for no apparent
> reason setting the HTML of a DOM object in iOS sometimes simply does
> not work. No errors are reported. Try/catch catches nothing. It simply
> does not work.
>

innerHTML is unreliable. You cannot build an complex application (DOM
wise) and assume it works. In the worst case it just starts failing on
pne day and you need to face the angry uses :(

It is the best to avoid the problem altogher and not to use innerHTML.

* Create new elements only through DOM manipulation

* Use innerText only

There are some DOM template libraries out there which allow you to
construct HTML structures from nested Javascript objects / arrays very
easily. Actually after certain point it's much more fun to use DOM
templating instead of old fashioned string templating and string
nodes.

Of course, this does not help you much if you need to place user
generated HTML content (WYSIWYG) from the server side to your app, but
it's not that common use case.

-Mikko

(Continue reading)

Daniel Pirone | 16 Mar 18:31
Favicon

Re: setting innerHTML failing occasionally ?

I did a quick search, and didn't see it this - thanks for pointing it out!

On Wed, Mar 16, 2011 at 12:54 AM, Shazron Abdullah <shazron.abdullah-dFG2o3VlNyPQT0dZR+AlfA@public.gmane.org> wrote:
http://blog.johnmckerrell.com/2007/03/07/problems-with-safari-and-innerhtml/

It's been discussed on this list previously as well (do a search on this list to see).

On 2011-03-16, at 12:38 AM, Daniel Pirone wrote:

> Howdy -
>
> I have a phonegap ( recent git head version ) based iOS app that does
> a lot of dynamic HTML generation  - mostly updating the innerHTML of
> divs and spans  with content fetched from a remote server.
>
> every couple of "interactions" , I will see a silent failure of  code
> roughly of the form:
>
>    document.getElementById("RestaurantLocationName").innerHTML =
> theName;
>
> Sometimes it will work, sometimes it doesn't ...  no obvious reasons
> why - I can try a second later, and it works again ...
>
> It happens in both the simulator and on real iPhones ...
>
> Is it possible that somehow the DOM needs to be told to sync or
> refresh or ... ?
>
> Suggestions ?
>
> Thanks in advance!
>
> - djp
>
> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phonegap-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> To unsubscribe from this group, send email to
> phonegap+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phonegap-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
phonegap+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phonegap-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
phonegap+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com

Gmane