Monday, May 2, 2011

Dynamically Including HTML Page in Other HTML Page

Finally after a good amount of research in Google I have found how to include a HTML page in another HTML page. We can insert a HTML page in one of the DIV or SPAN Tags of other HTML page. Below is the Java Script function for including a HTML page in another HTML page.

Function:

function clientSideInclude(id, url) {
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
var element = document.getElementById(id);
if (!element) {
  alert("Bad id " + id + "passed to clientSideInclude." +"You need a div or span element " + "with this id in your page.");
  return;
}
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    element.innerHTML = req.responseText;
  } else {
    element.innerHTML = "Sorry, your browser does not support " +  "XMLHTTPRequest objects. This page requires " + "Internet Explorer 5 or better for Windows, " + "or Firefox for any system, or Safari. Other " + "compatible browsers may also exist.";
  }
}

Example:

There are two HTML Pages by name one.html and two.html.

one.html:

<html>

<head>

<title>one</title>

</head>

<body>

Hello this is one.html

</body>

</html>

two.html:

<html>

<head>

<title>two</title>

</head>

<body>

<div onclick=”clientSideInclude(‘two’,’one.html’);”>Hello this is two.html</div>

<div id=”two”></div>

</body>

</html>

Explanation:

Include the above mentioned function in the two.html. and run the file two.html using any browser. when the text “Hello this is two.html” the function is called and the div with id “two” will be loaded with the text from the one.html.

Attach Java Script or CSS files dynamically using Java Script

If there is a need to dynamically load JS or CSS file then the following code is useful. just copy the below function in to a Java Script file and where ever the attachment is needed then call the function with the attributes as specified in the examples..

Function:

function dynamicload(filename, filetype)

{

if (filetype=="js") { //if filename is a JavaScript file

           var fileref=document.createElement('script')

           fileref.setAttribute("type","text/javascript")

           fileref.setAttribute("src", filename)

}

else if (filetype=="css") { //if filename is a CSS file

                    var fileref=document.createElement("link")

          fileref.setAttribute("rel", "stylesheet")

         fileref.setAttribute("type", "text/css")

         fileref.setAttribute("href", filename)

}

if (typeof fileref!="undefined")

        document.getElementsByTagName("head")[0].appendChild(fileref)

}

 

Example:

dynamicload("myscript.js", "js") //dynamically load to add .js file
dynamicload("mystyle.css", "css") //dynamically load to add .css file

Monday, March 28, 2011

HTML <button> tag

<button> tag is introduced in HTML 4.0. Almost all the new versions of the browsers support this tag.

This tag takes 4 attributes namely:

1. name

2. type

3. disabled

4. value

“type” attribute specifies the type of button. It takes 3 values. They are : Submit, Reset, Button.

If it is a “submit” button and the browser is IE then it submits the text present in between the button start and end tags. All other browsers submit the content of “value” attribute.

Sunday, March 27, 2011

Combine Multiple Text Files in Unix

To combine multiple text files in Unix we need to use the “cat” command.
Syntax: cat filename1 filename2 filename3 >> newfilename

Example: cat a.txt b.txt >> c.txt

In the above example we are combining the contents of the 2 text files in to a third text file. The new file “c.txt” contains the contents of “a.txt” and then the contents “b.txt”.

If the command “cat b.txt a.txt >> c.txt” is used then the new file contains the contents of “b.txt” first and then the contents of “a.txt”.

We can combine any number of text files to a single file. All we need to do is to specify the file names before the “>>” symbol which is the output redirection operator in Unix.

Thursday, March 24, 2011

String Comparision in Excel


  1. To compare strings in excel we need to use the EXACT function.
  2. EXACT function takes two arguments. If both the arguments are same(Case Sensitive) then the result will be TRUE else the result is FALSE.
  3. Syntax:  EXACT(arg1,arg2)
Below is a sample excel sheet on which we use the function.

  • =EXACT(A1,B1)  returns FALSE
  • =EXACT(A1,”Krishna”) returns FALSE
  • =EXACT(A1,”Krishna”) returns TRUE
  • =EXACT(“Krishna”,”Krishna”)  returns TRUE
  • =EXACT(“Krishna”,”Krishna”) returns FALSE