JScript - Launch a URL

Hi all, I am trying to launch a file using jscript.  Simply stated, all I want to really do is call a function that launches a new window.  My link is as follows: file:\\\c:\Test.txt.

I tried the following code which I found on experts exchange but it does not work...  Says ; expected down in the right hand corner in the web browser.


          {
               string jScript;
               jScript = "<SCRIPT language=\"javascript\"> window.open("file:\\\c:\Test.txt";);</SCRIPT>";
               this.Page.RegisterStartupScript("open",jScript );  
          }

Any help would be appreciated.  500 points!
jwebster77Asked:
Who is Participating?
 
ZvonkoConnect With a Mentor Systems architectCommented:
What about this:

          {
               string jScript;
               jScript = "<SCRIPT language=\"javascript\"> window.open(\"file:\\\\\\c:\\Test.txt\";);</SCRIPT>";
               this.Page.RegisterStartupScript("open",jScript );  
          }

Or with apostrophes:

          {
               string jScript;
               jScript = "<SCRIPT language='javascript'> window.open('file:///c:/Test.txt';);</SCRIPT>";
               this.Page.RegisterStartupScript("open",jScript );  
          }


0
 
BasilisciCommented:
You have forgot to escape some quotation marks, corrected line should look like this, I think:


 jScript = "<SCRIPT language=\"javascript\"> window.open(\"file:\\\c:\Test.txt\");</SCRIPT>";
0
 
jwebster77Author Commented:
I copied exactly what you mentioned and the \="javascript\" is underlined and the error says:

Cannot switch views:  Validation (INternet Explorer 6): If this attribute is enclosed in quotation marks, the qutation marks must match.
0
 
rama_krishna580Commented:
Hi,

try this...

<html><head>
<SCRIPT LANGUAGE='JavaScript'>
var password='theirpassword';
var name='username';

function WriteToFile() {
     var filename = 'c://temp.txt';
     var fso = new ActiveXObject('Scripting.FileSystemObject');
     if (fso.FileExists(filename)) {
          var a, ForAppending, file;
          ForAppending = 8;
          file = fso.OpenTextFile(filename, ForAppending, false);
          file.WriteLine(name);
          file.WriteLine(password);
          }
     else {
          var file = fso.CreateTextFile(filename, true);
          file.WriteLine(password);
          file.WriteLine(name);
          }
     file.Close();
     }

function ReadIt() {
     var filename = 'c://temp.txt';
     if (confirm('Do you want to see what we put on your computer?')) {
          var fso, a, ForReading;
          ForReading = 1;
          fso = new ActiveXObject('Scripting.FileSystemObject');
          file = fso.OpenTextFile(filename, ForReading, false);
          var name = file.readline();
          var password = file.readline();
          file.Close();
          document.write(name + '<br>');
          document.write(password);
     }
}
</SCRIPT>
</head>
<body onload='WriteToFile();ReadIt()'>
</body>
</html>

R.K
0
All Courses

From novice to tech pro — start learning today.