Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The JavaScript FAQ
Prev Home Next

External Files Within Layers

Question: Can I display an external HTML file as part of my page?

Answer: Yes, you can display an external HTML file on your page by using:

  • LAYER or ILAYER tags with SRC=FILENAME.HTM (in Netscape 4)
  • IFRAME tag with SRC=FILENAME.HTM (in Explorer 4+ and Netscape 6)
    You can use JavaScript to detect the browser name and version (see Client Information) and then generate the necessary IFRAME or LAYER tags.

    Here's an example:

    In the above example, we've created a JavaScript function insertExternalFile() for detecting the client browser and generating the necessary tags. In order to insert an external file, we called insertExternalFile() passing the file name as a parameter. The function also takes two other parameters: the width and height of the area where you'd like to display the inserted file. Thus, each of the external files inserted_file1.htm and inserted_file2.htm was embedded in the page using the following code:

    insertExternalFile("inserted_file.htm",layer_width,layer_height)
    

    The JavaScript code of the function insertExternalFile() is contained within the HEAD section of the page:

    <script language="JavaScript">
    <!--
    function insertExternalFile(fname,W,H) {
     if (navigator.appName.indexOf("Microsoft")!=-1
      || navigator.appName=="Netscape" 
         && parseInt(navigator.appVersion)>4
     ) 
     {
      document.write(''
      +'<IFRAME src="'+fname+'" scrolling="no" frameborder=0 border=0'
      +(W==null ? '' : ' width='+W)
      +(H==null ? '' : ' height='+H)
      +'></IFRAME>'
      )
     }
    
     if (navigator.appName=="Netscape" 
         && parseInt(navigator.appVersion)==4) {
      document.write(''
      +'<ILAYER>'
      +'<LAYER src="'+fname+'" '
      +(W==null ? '' : ' width='+W)
      +(H==null ? '' : ' height='+H)
      +'></LAYER></ILAYER>'
      )
     }
    }
    //-->
    </script>
    

    Copyright © 2000, Alexei Kourbatov

    The JavaScript FAQ
    Prev Home Next


  •  
     
      Mirrored with kind permission of Alexei Kourbatov Design by Interspire