DHTML Lab: HierMenus CENTRAL: Version 3.x FAQ #11 - dhtmlab.com | WebReference

DHTML Lab: HierMenus CENTRAL: Version 3.x FAQ #11 - dhtmlab.com

Frequently Asked Question #11

Entered: Sept 10, 1999



We are using IEWin, exclusively, in a controlled intranet environment. IE allows us to link directly to Word .doc files and Excel .xls files in link HREFs. These files are then displayed in the normal browser window. We are using the Heirarchical Menus script in a frameset.

When we use such URLs in the menu arrays, and attempt to navigate to them, IE generates an error. How can I prevent the error and open Word and Excel files in the main frame directly and keep the menu script active?

Internet Explorer will load the Word or Excel file, then choke when it checks the readyState of the main frame in the keepTrack() function:

function keepTrack() {
    if (menuLoc.document.readyState == "complete") {
    ...
}

Since the content of the main frame is NOT an HTML page, it has no compatible DOM, and no document object. The main frame no longer contains a Web page and the menus will cease to function, as would any script.

Solution:
Load the Word or Excel file into a standard HTML document, which is, in turn, loaded into the frame.
Option 1:
Since you want the content of the frame to be just the Word or Excel file, you can load it into an IFRAME that is the same size as the frame. Your frame page HTML should look like this:
<BODY TOPMARGIN=0 LEFTMARGIN=0 SCROLL=NO>
    <IFRAME
        SRC="myWordFile.doc" WIDTH="100%" HEIGHT="100%"
        FRAMEBORDER="No"></IFRAME>
</BODY>
Option 2:
The option above requires you to create one page for every Word or Excel document that you want loaded into the main frame. You also have to modify your arrays to point to .html files instead of .doc or .xls.

Looking at the necessary HTML, we notice that it is short enough to generate dynamically from our script. That is, we can create the page on-the-fly whenever a .doc or .xls file is linked to, by changing the linkIt() function to read:
function linkIt() {
    if (this.linkText.indexOf("javascript:")!=-1) {
        eval(this.linkText)
    }
    else {
        if (IE4 && (this.linkText.indexOf(".doc")!=-1 || this.linkText.indexOf(".xls")!=-1)) {
            with (menuLoc.document) {
                write("<BODY TOPMARGIN=0 LEFTMARGIN=0 SCROLL=NO><IFRAME SRC='"+ this.linkText +"' WIDTH=100% HEIGHT=100% FRAMEBORDER=No></IFRAME></BODY>");
                close()
            }
        }
        else menuLoc.location.href = this.linkText;
    }
}

We identify the page requested as a Word or Excel file, by checking for the .doc and .xls extensions. If we find them, we write the requisite HTML directly into the frame, erasing the old page, and creating a full-size IFRAME into which the .doc or .xls file is loaded.

The menus WILL be created even for this page, but they will be behind the IFRAME (see DHTML Diner). When the user returns to a normal page, the menus will be visible once more. If you want the menus and the IFRAME to co-exist, then position the IFRAME in such a way as to allow space for the menus to show. For example:

...<IFRAME STYLE='margin-left:200'...

will leave 200 pixels on the left in case you want the menus to appear there.


Produced by Peter Belesis and

All Rights Reserved. Legal Notices.
Created: Dec 29, 1998
Revised: June 26, 2001

URL: https://www.webreference.com/dhtml/hiermenus/version3/faq/faq11.html

Justtechjobs.comFind a programming school near you






Online Campus Both