accessing head section

Discussion in 'Javascript' started by William Starr Moake, Jul 2, 2004.

  1. This may be difficult to understand unless you are familiar with the
    design mode feature built into Internet Explorer 5.5+. I used this
    feature to develop a browser-based WYSIWYG HTML editor for offline
    use, but I have run into a serious problem that I can't solve.

    innerHTML and outerHTML access the <body> section of the web page
    under construction, but I was able to hack together some javascript to
    access the <head> section for the user to insert CSS and scripts from
    popup form-based code generators. The problem is I can only access the
    <head> section twice. When a third insertion of script or CSS is
    attempted, it is placed in the <body> section. Amazingly, this still
    works for IE, but it's bad coding and I'm sure it doesn't work in
    other browsers.

    Here is the first two insertions that work:

    function generatecss(){
    var html = opener.iView.document.body.outerHTML;
    var html_txt = "<html>" + "<head>" + "<style>" +
    '<!--a:hover{'+thesheet+'}-->' + "</style>\n";
    opener.iView.document.write(html_txt);
    }
    (iView is an iframe used as an editing window for the page under
    construction, 'the sheet' is the form output for CSS hover links. Note
    that I ended the insertion at </style> without closing the <head>
    tag.)

    function metaTag(form){
    var html = opener.iView.document.outerHTML;
    var html_txt = "<head>" + txt + "</head>" + "<body>" + "Page Content
    Begins Here" + "</body>" + "</html>\n";
    opener.iView.document.write(html_txt);
    }
    (txt is the form output for meta tags. Note that I had to add body
    text and close the <body> and <html> tags. Otherwise, the iView focus
    remains in the (invisible) head section and no content can be added to
    the body section.)

    After hover link properties and meta tags are added, scripts and CSS
    that are directed to the head section in the same way end up in the
    body section instead. Any ideas about how I could change the functions
    so that any number of CSS and script insertions could be made to the
    head section as the page is being designed? I have code generators for
    rollover buttons, popup windows etc. that require data in the head.
    William Starr Moake, Jul 2, 2004
    #1
    1. Advertising

  2. William Starr Moake

    Jim Ley Guest

    On 1 Jul 2004 20:18:13 -0700, (William Starr
    Moake) wrote:

    >innerHTML and outerHTML access the <body> section of the web page
    >under construction, but I was able to hack together some javascript to
    >access the <head> section for the user to insert CSS and scripts from
    >popup form-based code generators. The problem is I can only access the
    ><head> section twice. When a third insertion of script or CSS is
    >attempted, it is placed in the <body> section. Amazingly, this still
    >works for IE, but it's bad coding and I'm sure it doesn't work in
    >other browsers.


    It almost certainly does actually, the HEAD and BODY elements are
    almost completely normalised into irrelevance in all UA's

    Anyway, just use document.documentElement rather than document.body
    when you want to work on the whole document and not just the body.

    Jim.

    --
    comp.lang.javascript FAQ - http://jibbering.com/faq/
    Jim Ley, Jul 3, 2004
    #2
    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. Brian W
    Replies:
    10
    Views:
    756
    Brian W
    Jul 2, 2003
  2. Sergey Morkovkin
    Replies:
    5
    Views:
    17,284
    gamcfarlane
    Jul 14, 2009
  3. showme

    PHP and ASP.NET go HEAD to HEAD

    showme, Jul 8, 2004, in forum: ASP .Net
    Replies:
    13
    Views:
    711
    Sherif ElMetainy
    Jul 10, 2004
  4. Karl
    Replies:
    0
    Views:
    385
  5. Jiho Han

    Write into <HEAD></HEAD> section?

    Jiho Han, Jan 14, 2004, in forum: ASP .Net Building Controls
    Replies:
    6
    Views:
    221
    Sam Fields
    Jan 16, 2004
Loading...

Share This Page