×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    45

    document.getElementById().innerHTML Doesn't work on device

    While it work on emulator.

    Any idea?


    Snippet of what I did: (work on emulator, failed on X3 device)

    Code:
    tmpText = tmpText+ "mwl.insertHTML(\"#breadcrumb2\", \" | detail\");";
    tmpText = tmpText+ "mwl.removeClass(\"#contentHolder\", \"show\");";
    tmpText = tmpText+ "mwl.addClass(\"#contentHolder\", \"hide\");";
    tmpText = tmpText+ "mwl.removeClass(\"#contentDetailHolder\", \"hide\");";
    tmpText = tmpText+ "mwl.addClass(\"#contentDetailHolder\", \"show\");";
    tmpText = tmpText+ "mwl.scrollTo(\"#header\");";
    tmpText = tmpText+ "mwl.insertHTML(\"#contentDetailHolder\", document.getElementById(\"news_detail_" + item.link_id + "\").innerHTML);";

  2. #2
    Nokia Developer Expert
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: document.getElementById().innerHTML Doesn't work on device

    Hi,

    Could you elaborate context where tmpText is used?

    -Ilkka

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    45

    Re: document.getElementById().innerHTML Doesn't work on device

    Hi,

    Thanks for quick reply.

    Here's the WGT: http://dl.dropbox.com/u/1636195/LintasBerita_v1.wgt

    You'll see the problem on step after clicking 'news' in 'detail news'

  4. #4
    Nokia Developer Expert
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: document.getElementById().innerHTML Doesn't work on device

    Hi,

    Bad news.
    Use case can be simplified to following form
    Code:
    <div id="source">
    		source
    	</div>
    	
    	<div id="dest">
    		destination
    	</div>
    	
    	<div onclick="mwl.insertHTML('#dest', document.getElementById('source').innerHTML);">
    		Click me  
    	</div>
    Simulator is capable to process JavaScript and it will interpret document.getElementById as Javascript sentence. Then again Ovi browser does not recognize it and will use it only as a plain text.

    From the log:
    Code:
    Translated { <div onclick="mwl.insertHTML('#dest', document.getElementById('source').innerHTML);"></div> } to { <div onclick="mwl.insertHTML('#dest', document.getElementById('source').innerHTML);" class="x149" n="66"/> }
    After clicking "Click me" on a device div "dest" is populated with "document.getElementById('source".

    So some sort of workaround is needed. Unfortunately I don't have one to offer for now.

    -Ilkka

  5. #5
    Nokia Developer Expert
    Join Date
    Apr 2008
    Location
    Washington, DC USA
    Posts
    12

    Re: document.getElementById().innerHTML Doesn't work on device

    I ran into a similar problem (http://discussion.forum.nokia.com/fo...wl.switchClass))

    I think the issue has to do with combining MWL and regular DOM commands in the same place. The simulator can handle this, but the device does not. I solved the problem in my app by moving DOM code to a separate JS function.

    I suspect that this issue is related to the proxy server architecture of web apps. MWL commands execute locally on the client, while other JS (like document.getElementById()) execute on the proxy server. Perhaps the device gets confused when these are combined...
    --Oren Levine
    Web developer portfolio manager, Nokia
    oren.levine@nokia.com

  6. #6
    Registered User
    Join Date
    Feb 2011
    Posts
    45

    Re: document.getElementById().innerHTML Doesn't work on device

    I solved the problem in my app by moving DOM code to a separate JS function.
    Can you share some code snippet?

  7. #7
    Nokia Developer Expert
    Join Date
    Apr 2008
    Location
    Washington, DC USA
    Posts
    12

    Re: document.getElementById().innerHTML Doesn't work on device

    Quote Originally Posted by artinteg View Post
    Can you share some code snippet?
    OK.

    Original code combines MWL and DOM calls:
    Code:
    <img id="get_bus" src="img/go_button.png" onclick="mwl.switchClass('#slider', 'show_toc', 'show_scratchpad'); 
    					mwl.insertHTML('#subtitle', 'Next bus at stop ID ' + document.getElementById('stop_id').value);
    					getAction1(document.getElementById('stop_id').value);" alt="" />
    Modified code: moved the DOM logic from the index.html page to the getAction1() JS function. Note that I replaced the original text with "Loading...." since there will be a wait until the server processes the JS.
    Code:
    <img id="get_bus" src="img/go_button.png" onclick="mwl.insertHTML('#subtitle', 'Loading . . .' ); 
    									mwl.switchClass('#slider', 'show_toc', 'show_scratchpad'); 
    								getAction1();" alt="" />
    ...and the function itself
    Code:
    function getAction1()
    {
    	var sid = document.getElementById('stop_id').value;
        mwl.insertHTML('#subtitle', 'Next bus at stop ID ' + sid);	
    	
    	getNextBus(sid);
    	
        document.getElementById('scratchpad').innerHTML = '<div>' + sid + '</div>';
    }
    Hope this is useful.
    --Oren Levine
    Web developer portfolio manager, Nokia
    oren.levine@nokia.com

  8. #8
    Registered User
    Join Date
    Feb 2011
    Posts
    45

    Re: document.getElementById().innerHTML Doesn't work on device

    ow, like that. But, it will create unneeded server roundtrip for my application.

  9. #9
    Nokia Developer Expert
    Join Date
    Apr 2008
    Location
    Washington, DC USA
    Posts
    12

    Re: document.getElementById().innerHTML Doesn't work on device

    Quote Originally Posted by artinteg View Post
    ow, like that. But, it will create unneeded server roundtrip for my application.
    True, but I don't think there's a way around that right now.
    --Oren Levine
    Web developer portfolio manager, Nokia
    oren.levine@nokia.com

Similar Threads

  1. mbm doesn't work on device
    By yopyop in forum Symbian
    Replies: 6
    Last Post: 2010-02-23, 15:06
  2. J2ME application works on emulator, doesn't work on device
    By badzio in forum Bluetooth Technology
    Replies: 0
    Last Post: 2008-07-28, 13:32
  3. Replies: 1
    Last Post: 2008-04-28, 10:16
  4. RDebug::print doesn't work on-device
    By enigma19971 in forum Symbian Tools & SDKs
    Replies: 3
    Last Post: 2008-04-04, 09:13
  5. Replies: 2
    Last Post: 2007-12-13, 10:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×