- 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.

11th Jul 2017, 11:18 PM
TheDavyLoper
TheDavyLoper - avatar
3 Réponses
+ 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 ☺
12th Jul 2017, 1:04 AM
Pao
Pao - avatar
+ 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); }
12th Jul 2017, 7:40 AM
Pao
Pao - avatar
+ 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?
12th Jul 2017, 2:55 AM
TheDavyLoper
TheDavyLoper - avatar