FAQ Topic - How do I modify the current page in a browser?

Discussion in 'Javascript' started by FAQ server, Apr 23, 2007.

  1. FAQ server

    FAQ server Guest

    -----------------------------------------------------------------------
    FAQ Topic - How do I modify the current page in a browser?
    -----------------------------------------------------------------------

    Using the DOM the non-standard but widely implemented innerHTML
    extension, the following would be sufficient to modify the content
    of any element that can have content:
    ` <div id="anID">Some Content</div> ` with script of
    ` document.getElementById("anID").innerHTML=
    "Some <em>new</em> Content"; `
    Where "anID" is the (unique on the HTML page) ID attribute value
    of the element to modify.

    The script below adds support for ` document.all ` capable browsers.
    Support for NN4 is also possible, but certain issues mean that
    it is not listed here. Using the example above, the call would
    be written:
    ` DynWrite('anID',"Some <em>new</em> Content") `
    With the below code also in the page:

    DocDom = (document.getElementById?true:false);
    DocAll = (document.all?true:false);
    DocStr=''
    if (DocAll) DocStr="return document.all[id]"
    if (DocDom) DocStr="return document.getElementById(id)"
    GetRef=new Function("id", DocStr)
    if (DocStr=='') { DynWrite=new Function("return false") } else {
    DynWrite=new Function("id", "S", "GetRef(id).innerHTML=S; return true")
    }

    An alternative DynWrite function:

    http://www.jibbering.com/faq/faq_notes/alt_dynwrite.html

    http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/innerHTML.asp

    http://www.mozilla.org/docs/dom/domref/dom_el_ref8.html#1018427


    ===
    Postings such as this are automatically sent once a day. Their
    goal is to answer repeated questions, and to offer the content to
    the community for continuous evaluation/improvement. The complete
    comp.lang.javascript FAQ is at http://jibbering.com/faq/index.html.
    The FAQ workers are a group of volunteers.
     
    FAQ server, Apr 23, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. FAQ server
    Replies:
    1
    Views:
    98
    PDannyD
    Aug 28, 2006
  2. FAQ server
    Replies:
    0
    Views:
    74
    FAQ server
    Oct 25, 2006
  3. FAQ server
    Replies:
    0
    Views:
    96
    FAQ server
    Dec 22, 2006
  4. FAQ server
    Replies:
    2
    Views:
    97
    Dr J R Stockton
    Feb 21, 2007
  5. FAQ server
    Replies:
    0
    Views:
    91
    FAQ server
    Jun 23, 2007
Loading...

Share This Page