Solved

JScript - Launch a URL

Posted on 2006-11-15
6
1,436 Views
Last Modified: 2008-03-04
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!
0
Comment
Question by:jwebster77
6 Comments
 
LVL 6

Expert Comment

by:Basilisci
ID: 17947847
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
 

Author Comment

by:jwebster77
ID: 17947908
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
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 17949383
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
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 17950688
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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now