#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Posts
    149
    Rep Power
    13

    Meta tages & CSS using DOM functions?


    I'm using DOM functions from one frame to create layers in another frame, which is empty, initially. The frameset is defined below.

    My site initally defines a frameset that opens a page into a 'hidden' frame (CONTROLFRAME), that then calls functions
    to render the site in the visible frame (DISPFRAME):

    <HTML><HEAD><TITLE>DOM Testing</TITLE></HEAD>
    <FRAMESET ROWS="50%,*" SCROLLING=AUTO NORESIZE BORDER=0>
    <FRAME SRC="domcontrol.html" NAME=CONTROLFRAME SCROLLING=NONE NORESIZE>
    <FRAME SRC="about:blank" NAME=DISPFRAME SCROLLING=NONE NORESIZE>
    </FRAMESET>
    </HTML>

    I have been able to now successfully render layers, and other things into the blank 'DISPFRAME' using DOM functions, createElement, appendChild, etc.
    Before I implemented the use of DOM functions, I explicitly called
    document.write() from the CONTROLFRAME to write HTML into the DISPFRAME.
    When I did this, I wrote ALL the HTML, including the
    <HTML><HEAD><TITLE>....., etc. However, I also had two <META> tags and a <LINK> tag written as well, but since I've now abandoned that explicit writing, I don't have those tags defined in the document head anymore.

    So my question is: Is there a way to create these tags using DOM functions as well?

    I've tried the following code, but it didn't seem to work:

    var _TEMP_OUTP = top.DISPFRAME.document.createElement("META");
    _TEMP_OUTP.setAttribute("http-equiv","Expires");
    _TEMP_OUTP.setAttribute("content","-1");
    top.DISPFRAME.document.head.appendChild(_TEMP_OUTP);

    ... and ...

    var _TEMP_OUTP01 = top.DISPFRAME.document.createElement("LINK");
    _TEMP_OUTP01.setAttribute("REL","stylesheet");
    _TEMP_OUTP01.setAttribute("TYPE","text/css");
    _TEMP_OUTP01.setAttribute("HREF","style01.css");
    top.DISPFRAME.document.head.appendChild(_TEMP_OUTP01);

    How else might I be able to create these tags?

    I've also tried top.DISPFRAME.document.getElementsByTagName("BODY")[0].appendChild(_TEMP_OUTP01);

    Thanks,

    - coredumped.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    I think createElement and appendChild is the only compliant way of doing it. The HTML DOM has no 'easy' way of adding elements. As for why your code doesn't work, I think only elements in the body tag can be added to affect the document after the initial load? I can't remember...I'll think about it some more, but now it's too late.

    You could use other methods, like innerHTML to create elements, but then you run into browser issues. Methods like these are really only useful for specific environments where you know what the client is going to be.

IMN logo majestic logo threadwatch logo seochat tools logo