I'm trying to create a HTA application, that can open programs(exe, bat etc..) locally on the computer.
This will be used on a Kiosk PC, where the users don't have access to the desktop etc.
But have some problems, with finding a script that works..
Right now I'm using this script:
<script type="text/javascript">
function runApp(which) {
WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run (which,1,true);
}
</script>
And this is how my links looks:
<a
href="javascript:window.location.href=window.location.href"
onclick="runApp('file://C:/Tools/program.exe');parent.playSound('assets/sounds/startsound.mp3');"
onmouseover="playSound('assets/sounds/hover.wav');"
unselectable="on"
style="cursor: hand; display: block;">Start Program
</a>
The problem with this script, is that some of the programs I open from the launcher HTA are placed below the HTA app that runs in fullscreen.. So I need to ALT+TAB to switch to them..
I have been searching for another script, and found this HTA sample, which looks like a better way to do it:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=9">
<HTA:APPLICATION
APPLICATIONNAME="Open link with chrome browser"
BORDER="THIN"
BORDERSTYLE="NORMAL"
ICON="Explorer.exe"
INNERBORDER="NO"
MAXIMIZEBUTTON="NO"
MINIMIZEBUTTON="NO"
SCROLL="NO"
SELECTION="NO"
SINGLEINSTANCE="YES"/>
<META HTTP-EQUIV="MSThemeCompatible" CONTENT="YES">
<title>Test HTA</title>
<SCRIPT LANGUAGE="VBScript">
'************************************************************************************
Option Explicit
Function Executer(StrCmd)
Dim ws,MyCmd,Resultat
Set ws = CreateObject("wscript.Shell")
MyCmd = "CMD /C " & StrCmd & " "
Resultat = ws.run(MyCmd,0,True)
Executer = Resultat
End Function
'************************************************************************************
Sub window_onload()
CenterWindow 400,320
End Sub
'************************************************************************************
Sub CenterWindow(x,y)
Dim iLeft,itop
window.resizeTo x,y
iLeft = window.screen.availWidth/2 - x/2
itop = window.screen.availHeight/2 - y/2
window.moveTo ileft,itop
End Sub
'************************************************************************************
</script>
</head>
<p>Links :</p>
<ol>
<li>EXE test</li>
<li>Bat test</li>
<li>Chrome App Test</li>
</ol>
<BODY>
</body>
</html>
The problem with the script, is that I need to use:
<meta http-equiv="X-UA-Compatible" content="IE=9">
And If I add it to the sample above, it breaks and show me this error when I run the HTA:
An error has occured in the script on this page. Line: 46 Char: 31
Error: Expected ";" Code: 0
So looks like something breaks, with this linie and char 31 is: Call Executer
<li>EXE test</li>
If I don't use IE=9 on my HTA program launcher app, I get lots of error with the jquery that I use.
I have no prior experience with hta, vbs and only a little java.. So I have to use whatever scripts I can find.
Can anyone tell me, why this don't work with IE=9 content tag?
Please refer to the following sample code to launch app using HTA:
<html>
<head>
<title>Application Executer</title>
<HTA:APPLICATION ID="oMyApp"
APPLICATIONNAME="Application Executer"
BORDER="no"
CAPTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
SCROLL="no"
WINDOWSTATE="normal">
<script type="text/javascript" language="javascript">
function RunFile() {
WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("c:/windows/system32/notepad.exe", 1, false);
}
</script>
</head>
<body>
<input type="button" value="Run Notepad" onclick="RunFile();"/>
</body>
</html>
More detail information, your could check
How to execute a Local File using HTML Application?
Related
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</head>
<body>
<p>Привет Мир!</p>
<script type="text/javascript">var gtElInit = function gtElInit() {var lib = new google.translate.TranslateService();lib.translatePage('ru', 'en', function () {});}</script>
<script type="text/javascript" src="https://translate.google.com/translate_a/element.js?cb=gtElInit&client=wt"></script>
</body>
</html>
Example 2
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</head>
<body>
<p>Привет Мир!</p>
<script type="text/javascript" src="https://translate.google.com/translate_a/element.js?cb=gtElInit&client=wt"></script>
<script type="text/javascript">var gtElInit = function gtElInit() {var lib = new google.translate.TranslateService();lib.translatePage('ru', 'en', function () {});}</script>
</body>
</html>
When run this page localy from desktop in Chrome - it works (russian words after page page load translate to english). So it works well in snippet here!
But when put page to website and run like normal site from web - it DONT WORK (russian words dont translate). Webpage here: http://www.shram.kiev.ua/bak/1.shtml
Error: Uncaught TypeError: google.translate.TranslateService is not a constructor
I really dont know js but i trully need fix. Help pls. And pls give fix to my topic, because i read all topics about "is not a constructor" but dont understand :(
You need to load the translate library before you try to use it. On an HTML page, <script> tags are loaded in the order they appear, so you need to move the script tag loading Google translate above the script tag where you are trying to use it.
I'm trying to make a simple page with JS which generates Batch Scrips based on user input.
This is the prototype code and works fine with Chrome, but clicking on link with Firefox downloads the file as .txt (e.g.: file.bat.txt) and IE is completey unresponsive to the link
Where am i going wrong?
Any issues with "data:text/plain;base64,"?
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
</head>
<body>
click here
<script>
var bat_source = "#echo off\necho Hello world\npause";
document.querySelector("a").href = 'data:text/plain;base64,' + btoa(bat_source);
</script>
</body>
</html>
I am developing a test app in PhoneGap build. Currently I'm trying to redirect to a page when the app loads. But when I tried to do that, it is not redirecting, instead staying in index.html page only. I am using TestObject for testing the app.
index.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" charset="utf-8">
function init() {
document.addEventListener("deviceready", onDeviceReady, true);
}
function onDeviceReady() {
alert("Device is ready");
}
</script>
</head>
<body onload="init();">
<input type="button" onclick="location.href='http://google.com';" value="Go to Google" />
Hai welcome to my app
</body>
</html>
config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.mydomain.mobileApp"
versionCode = "1"
version = "1.0.0" >
<!-- versionCode is Android only -->
<!-- version is in major.minor.patch format -->
<name>My App</name>
<description>
An example for phonegap build app which wont show up in the playstore.
</description>
<author href="https://YourWebsite.com" email="yourEmail#goesHere.com">
Name Of The Author
</author>
</widget>
When I test this in browser, on clicking button it will redirect to http://google.com. But when I upload the apk (build from phonebuild) and upload to TestObject, button is coming. But on clicking it nothing happens. When I test the app,I'm getting like this.
Can anyone help me to find the issue. Thanks in advance.
You need to include cordova in your application
and try this one as well
document.addEventListener("deviceready", function(){
alert("Device ready Fire");
},true);
Include phonegap.js in head section of HTML file and do not make the click event handler inline. Register the event handler in script part. And also make sure you have included whitelist plugin. Try following code:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript">
function myFun(){
document.getElementById("myBtn").addEventListener("click", function(){
location.href='http://google.com';
});
}
</script>
</head>
<body onload="myFun()">
<button id="myBtn">Go to Google</button>
Hai welcome to my app
</body>
</html>
I have been through 3 simple tutorials on how to get started with JavaScript using VS 2010 and they all unanimously describe the basic steps of creating a project through File, New, Project, ASP.NET Empty Web Application and then adding a JavaScript file through Add, New Item and finally adding an HTML page to the project.
The contents of my two files are as follows, as described in all basic tutorials, like a HelloWorld program:
JScrip1.js
function add(a, b)
{
return a + b;
}
HTMLPage1.htm
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My page title!</title>
<script type="text/javascript" src="JScript1.js" />
</head>
<body>
<script type="text/javascript" >
alert("Sum of 3 and 4 = " + add(3, 4));
</script>
</body>
</html>
In all the tutorials, upon doing a right-click on the HTML component and choosing View in Browser, it compiles and shows an alert window with the result (7) but mine only shows the tab with the title, and a pop-up message saying that ASP.NET Development Server is running on port 56044
The page that opens has the following URL: http://localhost:56044/HTMLPage1.htm
What am I missing? Why is my html page completely blank?
RESOLVED by changing my HTML script to the following, thanks to Jared
<!DOCTYPE html PUBLIC>
<html>
<head>
<title>My page title!</title>
<script type="text/javascript" src="JScript1.js"></script>
</head>
<body>
<script type="text/javascript" >
alert("Sum of 3 and 4 = " + add(3, 4));
</script>
</body>
</html>
The final answer was that <script type="text/javascript" src="JScript1.js" /> needed changed to <script type="text/javascript" src="JScript1.js"></script>. Script tags are not self closing. Apparently browsers don't complain and just silently ignore the tag. :P
Is your browser blocking popups? If so, you can change the alert() command to console.log() command. That should be safer. (Press F12 to open the browsers developer tools and look for a console tab to see the console.log() output)
FYI: The console log will also show javascript errors and such. Like if it can't load the JScrip1.js file.
I'm no js expert but I've minimised my faulty script and tried to localise the fault without success. You can find the actual page at www.trinitywoking.org.uk. but my minimal test case is
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<title>MinTestCase</title>
<script>window.onload = function () { // Don't run script until page is loaded
var votd = new Array();
votd[129]="Mount Sinai was all smoke because God had come down on it as fire.";
// Prepare today's string for display
document.getElementById("keyverse").innerHTML="<p> " + votd[(129)] + "</p> ";
}
</script>
</head>
<body>
<h1>Target paragraph follows </h1>
<p id="keyverse">
</p>
</body>
</html>
This runs and displays correctly on all browsers except IE lte 8.
A second script runs on all browsers so it doesn't look like a permissions issue.
I'll be very grateful for any help with this.
Thanks.
Remove the <p> tags in document.getElementById() line:
document.getElementById("keyverse").innerHTML=votd[(129)];
There are already tags where you try to edit the innerHTML. IE is a very picky browser.