Solved

JScript - Launch a URL

Posted on 2006-11-15
6
1,437 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

947 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

20 Experts available now in Live!

Get 1:1 Help Now