Running Batch file using Javascript - Firefox - javascript

This is important for me as I have a PRN file which can be printed only through command prompt. And I want to delete that file after the print command is given.
So these 2 commands can be executed using batch file only.
And when I try to use activexobject in javascript, my firefox browsers doesnt run it.
<script>
MyObject = new ActiveXObject("WScript.Shell");
function Runbat()
{
MyObject.Run("\"D:\\abc.bat\"");
}
</script>

Together in a html page.
I've found this one and it seems working properly :)
<html>
<head>
<script language="JavaScript" type="text/javascript">
MyObject = new ActiveXObject("WScript.Shell")
function Runbat()
{
MyObject.Run("\"D:\\test.bat\"");
}
</script>
</head>
<body>
<h1>Run a Program</h1>
This script launch the file any bat File<p>
<button onclick="Runbat()">Run bat File</button>
</body>
</html>
Now I don't really know if you are already working with exaclty that solution, if so, and you are still facing this issue in firefox you may need to investigate a little bit more in browser security to know if that is even possible as of this post states that:
No, that would be a huge security breach. Imagine if someone could run
format c:
whenever you visted their website.

Related

paper.js causing Reference Error with typo that has been corrected

I've been using javascript and paperscript to make a test program and have an interesting problem. I got this error message: Uncaught ReferenceError: veiw is not defined, I realised that I had mis-spelled view and corrected it in my code. But for some reason the error message persised, I've restarted my computer and used ctrl+f to search for 'veiw' in my files, but still the error message persists.
Here is my current code:
console.log("Hi");
view.onFrame = function(event){
project.importSVG('.../mario.svg');
};
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="./scripts/paper-full.js"></script>
<script type="text/paperscript" src="./scripts/script.js" canvas="myCanvas"></script>
</head>
<body>
<canvas id="myCanvas" width="200" height="100"
style="border:1px solid #d3d3d3;">
</canvas>
</body>
</html>
And I don't know if this is relevant but there seems to be a file generated by paper js each time the webpage is loaded called VM followed by a number.
document.__paperscript__ = function(paper,project,setup,clear,paper) {var module = { exports: {} }; veiw.onFrame = function(event){
project.importSVG('.../mario.svg');
};
//paper.setup(htmlCanvas);
//paper.project.clear();
//paper.project.importSVG('mario.svg');
return module.exports;
}
As you can see both the type and a few comments that have since been removed from the source file are still here. But I have saved the file and reloaded the page (using the url:http://localhost:8000/html.html with python's http.server running the server).
I am clueless as to what is causing this, and I can't find a reference to veiw anywhere in any of my files. Please help me. I'm being haunted by a typo I made a week ago. It won't go away.
I figured it out. And I'm posting this so other people don't have the same problem. This occurs because chrome, which I am using saved webpages so they load faster, so when you change your code... it recognises that it is the same page and doesn't load the new stuff. This can be fixed by going to your chrome history chrome://history/ and clicking 'clear browsing data' then click 'advanced' select 'cached images and files' and unselect everything else, then just set the time at the top so that you don't delete too many things you don't want to.
NOTE:
Doing this wont delete any important data, the only reason not to select 'Time range: ALL TIME' is so that webpages load faster, which is the reason this data is stored in the first place.

ReferenceError when calling function in external script from a script tag

I feel like there is something very little I'm doing wrong, but I can't find it. I can't figure out how to call an externally-defined function from within a script tag, it keeps giving me ReferenceError's.
I've reduced my code to the most minimal, so here's what I've got. This is my HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<button id="mrbutton" type="button">Mr Button</button>
<div id="barChart"></div>
<script src="d3/d3.min.js"></script>
<script src="d3/charts/bar.js"></script>
<script>
chartParams = {};
document.getElementById('mrbutton').addEventListener('click', () => {createBarChart(chartParams)});
</script>
</head>
</html>
d3/d3.min.js is D3 version 3. Here's what I have in d3/charts/bar.js:
'use strict';
const createBarChart = params => {
console.log('hello there!');
};
console.log('script loaded!');
But when I load up the page, the Javascript console spits out:
script loaded!
Uncaught ReferenceError: createBarChart is not defined
If I move the code in d3/charts/bar.js into the <script> tag in the HTML, it works fine, but I want to reuse the code so I want it external. What am I doing wrong? Why can't I call createBarChart?
Update: Using Babel to compile down to Ecmascript2015 doesn't change anything, still the same ReferenceError. Also changed the event listener to an arrow function.
Update: I removed the D3 code and am just calling a console.log(), but still no luck.
I got it to work. Not sure if this will help anyone else (hopefully it can), but I just restarted my computer. That's all; no code changes whatsoever. My original code works fine now (even the original .addEventListener()).
It wasn't a browser caching issue, since I tried several browsers in private mode, and I still really don't know what the problem is. If anyone has any idea what it was, please do comment, I'm still puzzled despite being able to move on.

Options to store data on desktop, using webpage

Goal:
To sum it up, I'm trying to replace an excel spreadsheet. I'm creating an application that will run in IE9, but does not connect to the internet or an intranet (I know, I know. Just bear with me. If you're curious read more below). It needs to use CRUD (create, read, update, and delete) methods on a set of data that changes daily. The dataset must persist even when the browser is closed.
Question:
What options are available, using javascript and html, for storing data on the local computer the web page is accessed on? I'm doing this at work, so there will be no server-side to this. I also will not be able to install any software on the computer, although I can download javascript plugins. The webpage will be loaded from a file on the computer, using Win 7 and IE9.
Background:
This deserves an explanation. I use an excel spreadsheet to track a set of data that changes daily. I'm learning HTML and javascript, and I can create a much better (and easier to use) solution as a webpage. I can create the UI / UX, but I'm having a difficult time figuring out how to store the data on the local computer. Any good suggestions?
Attempts:
Unfortunately, it seems localStorage is not an option. I'm attempting to use jStorage, but I've been running into problems there, also. A similar set of problems has been encountered using simpleStorage.
Thank you for considering, please let me know if any more info is needed, or if I need to clarify something.
Addendum:
Localstorage, and other forms of HTML5 storage, do not work. Officially it does, unofficially it is very buggy. See blog post here, and SO answer here. Either way, with the following simple code:
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Backlog Tracker</title>
<script src="jquery-2.1.1.min.js"></script>
<script src="backlog_localstorage.js"></script>
</head>
<body>
</body>
</html>
and javascript (ref as "backlog_localstorage.js" above):
$(document).ready(function(){
$("body").append("<button>Try It</button>");
$("button").click(function(){
localStorage.setItem("key1", "Hello");
console.log(localStorage.getItem("key1"));
});
});
... I get the following error: "SCRIPT5007: Unable to get value of the property 'setItem': object is null or undefined" on the line localStorage.setItem("key1", "Hello");
HTA (which is really just an html file with one extra tag and a different file extension) is one possible solution for windows users:
Important: Save as demo.hta to run on windows as an app
<!DOCTYPE html>
<html> <!-- some parts lifted from
http://msdn.microsoft.com/en-us/library/ms536496(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/ms536473(v=vs.85).aspx
-->
<head>
<title>State Saving Demo</title>
<hta:application id="App"
application="yes"
applicationname="demo"
icon="calc.exe"
border="thin"
caption="yes"
sysmenu="yes"
showintaskbar="yes"
singleinstance="yes"
sysmenu="no"
maximizeButton="yes"
minimizeButton="yes"
navigable="no"
scroll="yes"
contextmenu="no"
selection="no"
windowstate="normal" >
<!-- Use Internet Explorer 10 Standards mode (to use JSON, CSS3, etc...) -->
<meta http-equiv="x-ua-compatible" content="IE=10">
</head>
<body onload=loadMe() >
<h1 id=h1>Command-line args: </h1>
<h3>Persisted Text</h3>
<textarea rows=20 cols=100 id=mydata onchange=saveMe() >
You can change me and i won't forget!
</textarea>
<script>
document.title+=" - Today is " + Date(); // task/title bar demo
h1.innerHTML+= JSON.stringify( App.commandLine ); // optional invocation info here (much like a real app)
// app-specific custom code:
FILENAME="state.txt";
function saveMe(){save(FILENAME, mydata.value); }
function loadMe(){mydata.value=load(FILENAME) || mydata.value;}
// generic utils:
function load(filename) { //IE FSO file Loader
var file,
text="",
fso= new ActiveXObject('Scripting.FileSystemObject');
try{
file = fso.OpenTextFile(filename, 1, false);
text = file.readAll();
file.Close();
}catch(y){}
return text;
}
function save(filename, sData){ //IE FSO file Saver
var file,
fso = new ActiveXObject('Scripting.FileSystemObject');
file = fso.CreateTextFile(filename, 2, false);
file.write(sData);
file.Close();
return file;
}
</script>
</body>
</html>
I recently re-discovered HTAs, and they are not half bad. I don't think I would want to distribute and maintain them, but HTA's are an easy way to make simple desktop app using HTML, CSS, and JS. Its nice not to have to build anything to "recompile" the app after changes are made. saves a few steps compared to node-webkit, packaged apps, air, cordova, etc, but HTA's have a major downside: they only work on windows afaik...
Looks to me like you can use LocalStorage, the big question is how are you trying to store it? You can easily store an object/array into LocalStorage, and that object/array can be your data, then JS can output this into a table. If you're looking to store actual files then you're looking at something more like an ActiveX plugin.
http://caniuse.com/#search=localstorage
Alternatively if you have internet access through a desktop or a phone you can put this on Google Drive. This would be far easier than reinventing the wheel.

HTA page opening the program but not running the file

After downloading all the lecture videos and other resources of a course,I wanted to make a course page for myself for easy access.
And I want the video open in VLC Player.
I tried the following code:
<html>
<script type="text/javascript" language="javascript">
function RunFile()
{
WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("vlc -vvv F:/Vishnu.mp4", 2, false);
}
</script>
<button onclick="RunFile()">Click Me!</button>
</html>
Here I took a test video file Vishnu.mp4 in F: and tried opening it using an HTA page with the above mentioned code.
The problem is that the VLC Player opens but the file doesn't play.No error message is displayed.
After coming across this related question,I tried the Exec method.
But the same problem persists.VLC Player opens but the file doesn't play.And no error message are displayed.
I'm clueless about what went wrong.As per my understanding after reading this & this, the strCommand argument of the Run & Exec method must be the same string I would otherwise give in the command line to accomplish the task.
By the way,in case it's required:
1.My OS is Windows 7 Enterprise Ed
2.VLC Player version is 2.0.6 Twoflower
Any help is appreciated.
I tried embedding VLC player in the page.The file opens in the embedded player but keyboard shortcuts & other features like fast fwd,speeding up the video,equalizer etc don't work.
Is there any way to open the file in VLC Player.
Thanks for reading.
Make sure that vlc is added to the system path variables by running the video directly from the Command Processor: C:\>vlc -vvv F:/Vishnu.mp4
Or only: C:\>vlc to try to launch VLC itself.
I don't have vlc added to system path, but then I used vlc's full path.
The following ran on my Windows 7 PC:
<html>
<script type="text/javascript" language="javascript">
function RunFile()
{
WshShell = new ActiveXObject("WScript.Shell");
the_file = '"C:/\Program Files/\VideoLAN/\VLC/\vlc.exe" -vvv "file:///D:/Green BAK/Video/Kurzweil-1.mp4"';
alert(the_file);
WshShell.Run(the_file, 2, false);
}
</script>
<button onclick="RunFile()">Click Me!</button>
</html>

Cannot get Adobe AIR's ApplicationUpdaterUI() to work

Here is my problem - I'm trying to write a self-updating application, but I keep getting an error saying that runtime.air.update.ApplicationUpdaterUI() does not return a constructor.
Here's the relevant section of the code; there are other javascript files being included, but I don't think that any of them would be actively breaking AIR itself.
<html>
<head>
<script type="text/javascript" src="./js/AIRAliases.js"></script>
<script type="text/javascript" src="./js/jquery-1.3.1.js"></script>
<script src="ApplicationUpdater_UI.swf" type="application/x-shockwave-flash"></script>
<script>
$(document).ready( function() {
var appUpdater = new runtime.air.update.ApplicationUpdaterUI(); // line 64 in this example
}
</script>
</head>
<body> ... stuff ... </body>
</html>
And the error that I get when I test it is
TypeError: Value is not a constructor. Cannot be used with new.
at app:/index3.html : 64
at app:/js/jquery-1.3.1.js : 2912
at app:/js/jquery-1.3.1.js : 686
at app:/js/jquery-1.3.1.js : 2916
at app:/js/jquery-1.3.1.js : 2936
Verify the path in that script tag for the SWF, I'm guessing you do not have the reference to the ApplicationUpdater_UI.swf correct.
Air is basically complaining that it cannot find a runtime.air.update.ApplicationUpdaterUI() method to call anywhere, which likely means it can't find the SWF (or I suppose it's possible the SWF is corrupted).
Not sure if this is related, but neither $(document).ready nor .load will work if you load the .swf before the script. Make sure you put the .swf reference at the very bottom of your page.

Categories