facebook

document.write not supported ??

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #330909 Reply

    alonso100
    Member

    Hi,

    what´s wrong with this code: ??

    function dynamic_code(){
      var htmlcode =
          "<script type='text/javascript'>" +
          "document.write('Something here')" +
          "</script>"
          
      $('#m1-test2-html1').html(htmlcode);
    }

    I use it for feeding an HTML-element on the screen and all I get is a white page. If I feed the code for a table (with <table>, <thead>, <tbody>,<tr>, <td>, etc) it works fine. If I enter the code directly in the widget, then it also works.

    #330916

    alonso100
    Member

    Searching in the internet for a way to avoid using document.write I found that I can work with appendChild, so I created this example:

      
    function input_field(){
      var htmlcode =
      "<script type='text/javascript'>" +
          "var input1='';" +
          "input1 = document.createElement('input');" +
          "input1.setAttribute('type', 'text');" +
          "input1.setAttribute('size', '20');" +
          "input1.setAttribute('border', '0');" +
          "input1.setAttribute('value', 'Nombre:');" +
          "input1.setAttribute('id', 'field1');" +
          "input1.style.border = 'none';" + 
          "document.getElementsByTagName('body').appendChild(input1);" +
          //"alert(document.getElementsByTagName('body'));" +
      "</script>"
          
      $('#m1-test2-html1').html(htmlcode);
    }
    

    It works in any browser but not in MobiOne. Working with Alert I can see that input1 has been correctly created and can also get Body with “document.getElementsByTagName(‘body’)” but when I add a child to the object, then I get this error message:

    TypeError: Result of expression document.getElementsByTagName(‘body’).appendChild [undefined] is not a function.

    What is the problem here ?? is appendChild not supported in MobiOne ??

    #330925

    support-michael
    Keymaster

    @alonso100

    Will look into this tomorrow (Mon). My 1st thought is probably css issue or error in the code.

    #331014

    alonso100
    Member

    Hi,

    any news on this ??

    #331016

    support-michael
    Keymaster

    I haven’t tried running this code as it seems flawed in someways.

    0) where in the dom are you inserting this code? What type of html element is $(‘#m1-test2-html1’)? Is it the node of an hmlt widget or something else. Also you must keep in mind that MobiOne UI’s are laid out using CSS extensively.

    1) why generate a script to run javascript from a javascript function?
    What am I missing that you can’t just build your html string and add it directly w/o nesting it in a script?

    #331018

    alonso100
    Member

    The ‘#m1-test2-html1’ is the normal HTML widget and the code in the JS function is called in the event phoneui.documentReadyHandler. I insert the code in the *_custom.js file.

    I can enter the code directly in the event without need of building a JS function. I did it here for shortening the example. See that I display 2 examples and none is working correctly in the mentioned event.

    #331023

    Hi Alonso,

    The problem is with: document.getElementsByTagName(‘body’), that returns a list, so you can not add your input, instead that you could use:

    document.getElementById('m1-test2-html1').appendChild(input1)

    Let me know how it goes.
    Q: Where are you located? I noticed that you used “Nombre” in your input.

    #331024

    alonso100
    Member

    Hi,

    that works now but tell me, is this code not supported: ??

    "<script type='text/javascript'>" +
        "document.write('Something here')" +
    "</script>"
Viewing 8 posts - 1 through 8 (of 8 total)
Reply To: document.write not supported ??

You must be logged in to post in the forum log in