- 1
html and JavaScript codes to reboot and shutdown a mobile phone
I want to write a web code to be able to restart a phone and also be able to shut it down.
3 Respostas
+ 11
JavaScript is a client-side programming language, meaning you don't have access to a user's device from a webpage so you cannot run a shutdown command, you only have access to the browser, and due to security reasons it is very limited.
Though you could gain full control of a user's device if they lower their security settings in the browser and install other software or browser extension. There's this WshShell.Run method in JavaScript that is like running a command in your Command Prompt. You'd need to develop a proper client-side activeX control to do this, though It only works in IE, it could be used to launch a .bat file, but you won't be able to launch .exes from JavaScript unless the user downloads it, then you'd just need to trigger the function after a click event or something. Example of the function:
function RunBatFile() {
WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("c:/windows/system32/mybatfile.exe", 1, false);
}
Anyways, I think this question might be outside the scope of this learning platform ☺
+ 9
Well, yes and no, it is possible in some way, for instance, if you're making a mobile app with Cordova or PhoneGap you can use a plugin. But, you will require reboot/shutdown permission, I mean, your device needs to be rooted (Android) / jailbreak (iOS) because the app needs root privileges. What you need to do is create a plugin that will execute Java/Objective C code. Java (Android) example :
try {
Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot" });
proc.waitFor();
} catch (Exception ex) {
Log.i(TAG, "Could not reboot", ex);
}
+ 1
Maybe I didn't put my question right, can i make an app on my phone that can reboot and shut it down, using html and Javascript?