I am looking out for a way to open a .xls file which is in temp directory using javascript in IE and Firefox browser. I tried using the javascript as follows,
Suggest you use AJAX. Small API follows.
/* **************************** AJAX ************************** */
///
/// Source
/// http://www.quirksmode.org/js/xmlhttp.html
/// XMLHttpRequestForms is a local auxiliary variable
var XMLHttpRequestForms =
[
function ( ) { return new XMLHttpRequest ( ); },
function ( ) { return new ActiveXObject ( "Msxml2.XMLHTTP" ); },
function ( ) { return new ActiveXObject ( "Msxml3.XMLHTTP" ); },
function ( ) { return new ActiveXObject ( "Microsoft.XMLHTTP" ); }
];
// ******************************************* createXMLHTTPObject
// local entry point
/// createXMLHTTPObject is a helper function
function createXMLHTTPObject ( )
{
var xmlhttp = false;
for ( var i = 0; ( i < XMLHttpRequestForms.length ); i++ )
{
try
{
xmlhttp = XMLHttpRequestForms [ i ] ( );
break;
}
catch ( e )
{
continue;
}
}
return ( xmlhttp );
}
/// ************************************************ read_contents
// global entry point
///
/// read_contents ( url )
///
///
/// retrieves the contents of the specified URL
///
///
/// a string containing the URL whose contents are to be read
///
///
/// a string containing the contents of the URL
///
///
/// var text = read_contents ( "footer.ini" );
function read_contents ( url )
{
var request = createXMLHTTPObject ( );
if ( !request )
{
return ( null );
}
request.open ( 'GET', url, false );
request.setRequestHeader ( 'Content-Type', 'text/html' );
request.send ( );
return ( request.responseText );
}