This question already has answers here:
How to resolve the C:\fakepath?
(13 answers)
Closed 5 years ago.
<!DOCTYPE html>
<html>
<body>
<div align="center" style="width:800px" >
LocalShare:
<input type="file" id="FileUpload" onchange="selectFolder(event)" webkitdirectory mozdirectory multiple />
<p id="demo"></p>
<p id="demo1"></p>
<script>
function selectFolder(e) {
var txt = "";
var theFiles = e.target.files;
var relativePath = theFiles[0].webkitdirectory;
var relativePath = theFiles[0].webkitRelativePath;
var x = document.getElementById("FileUpload").value;
document.getElementById("demo").innerHTML = x;
document.getElementById("demo1").innerHTML = relativePath;
var folder = relativePath.split("/");
alert(folder[0]);
}
</script>
</body>
</html>
Output of the above code is:
C:\fakepath\filename
foldername
Here it is displaying folder name and path name. It is taking default value as "fakepath" but I need to find out exact path!
Well, Earlier it was allowed but due to security reason browser doesn't allow us to get client machine's internal details.
Related
This is my first question here and I am pretty new to js and html so please excuse if I'm missing something obvious.
Goal: I want to create a script, that creates a Folder in your Google Drive but only if it's not already existing. In that folder it should create a .txt that contains certain information. After that, I want a new Tab to automatically open the URL of the newly created txt-file.
If I insert a normal URL in my .html (like "https://www.google.com") it all works perfectly fine. However I'm stuck at the part where the Apps Script hands over the grabbed Url of the newly created file to my html.
Any help is appreciated!
Google Apps Script Code (Code.gs):
function myFunction() {
var FData = "Very important Data"
var destFolder = DriveApp.getFoldersByName("Folder"); //create Drive folder if not already created
var destFolder = destFolder.hasNext() ?
destFolder.next() : DriveApp.createFolder("Folder");
var fileName = "Status.txt"; //create txt file in that folder and add data to it
var newFile = destFolder.createFile(fileName,FData);
var url = newFile.getUrl(); //?GIVE THIS URL TO openUrl.html?
var htmlOutput = HtmlService.createHtmlOutputFromFile('openUrl').setHeight(100);
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Opening...');
}
HTML (openUrl.html):
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
var urlToOpen = url; //insert grabbed Url here
var winRef = window.open(urlToOpen);
google.script.host.close();
</script>
</head>
<body>
</body>
</html>
In your script, how about the following modification?
Google Apps Script side:
function myFunction() {
var FData = "Very important Data"
var destFolder = DriveApp.getFoldersByName("Folder");
var destFolder = destFolder.hasNext() ? destFolder.next() : DriveApp.createFolder("Folder");
var fileName = "Status.txt";
var newFile = destFolder.createFile(fileName, FData);
var htmlOutput = HtmlService.createTemplateFromFile('openUrl');
htmlOutput.url = newFile.getUrl();
SpreadsheetApp.getUi().showModalDialog(htmlOutput.evaluate().setHeight(100), 'Opening...');
}
HTML & Javascript side:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
var urlToOpen = "<?!= url ?>";
var winRef = window.open(urlToOpen);
google.script.host.close();
</script>
</head>
<body>
</body>
</html>
When myFunction() is run, a dialog is opened by HTML including url using HTML template.
Reference:
HTML Service: Templated HTML
This question already has answers here:
how do I set input from user to the value of an input?
(2 answers)
Closed 6 years ago.
I am not exactly new at coding,
But I am definitely an amateur (especially in Javascript), and I have just started a new project for personal purpose.
I can not seem to get my Javascript to print out my answer, and I do not want to move on with the project until I figure it out, because it is going to have more complicated calculations as I work on it.
My code is as below:
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<p>Enter Your Macros</p>
<p>Fats</p>
<input type="number" name="fats" id="fatInput"/><br>
<button onclick="myFunction()">Calculate</button><br>
<p id="todaysFat"></p>
<script>
function myFunction() {
var f = document.getElementById("fatInput").innerHTML;
document.getElementById("todaysFat").innerHTML = f;
}
</script>
</body>
</html>
Thank you for all of the help
try;
function myFunction() {
var f = document.getElementById("fatInput").value;
document.getElementById("todaysFat").innerHTML = f;
}
I don't think it's the innerHTML your want but the value of the INPUT.
So that's .value not innerHTML.
eg..
var f = document.getElementById("fatInput").value;
Change the innerhtml to value in the first line.
See the below code:
function myFunction() {
var f = document.getElementById("fatInput").value;
document.getElementById("todaysFat").innerHTML = f;
}
<p>Enter Your Macros</p>
<p>Fats</p>
<input type="number" name="fats" id="fatInput" />
<br>
<button onclick="myFunction()">Calculate</button>
<br>
<p id="todaysFat"></p>
This question already has answers here:
De-obfuscate Javascript code to make it readable again [duplicate]
(5 answers)
Closed 7 years ago.
I try to work with javascript from Chrome extension, and have some problems.
Big parts of code including in encode array
var _0x6790 = ["\x44\x4F\x4D\x53\x75\x62\x74\x72\x65\x65\x4D\x6F\x64\x69\x66\x69\x65\x64", "\x67\x65\x74", "\x3A\x76\x69\x73\x69\x62\x6C\x65", "\x69\x73", "\x24\x61\x70\x70\x6C\x79\x46\x6F\x72\x4C\x6F\x6F\x74\x42\x75\x74\x74\x6F\x6E", "\x65\x6E\x61\x62\x6C\x65\x64", "\x61\x75\x74\x6F\x63\x6C\x69\x63\x6B\x69\x6E\x67", "\x73\x65\x74\x74\x69\x6E\x67\x73", "\x6D\x61\x67\x69\x63", "\x63\x6C\x69\x63\x6B", "\x5F\x62\x69\x64\x49\x6E\x74\x65\x72\x6E\x61\x6C\x44\x65\x6C\x61\x79", "\x61\x75\x74\x6F\x62\x69\x64\x64\x69\x6E\x67", "\x23\x67\x6F\x6C\x64\x73\x6C\x69\x64\x65\x72", "\x73\x65\x74\x42\x69\x64", "\x6F\x6E", "\x5F\x69\x6E\x73\x74\x61\x6E\x63\x65"];
and is used like this:
$(document)[_0x6790[14]](_0x6790[0], function() {
How can I decode the values in the array?
this is a worked demo that can help you:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script>
function hex2a(hex) {
var str = '';
for (var i = 0; i < hex.length; i += 2) str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
document.getElementById('result').innerHTML=str;
}
</script>
</head>
<body>
<h1><u>Hex Decoder</u></h1><br>
<h3><u>Hex code</u></h3>
<textarea id="hexcode" rows="4" cols="50"></textarea><br>
<button type="button" onclick="hex2a(document.getElementById('hexcode').value)">decode</button><br>
<h3><u>Result</u></h3>
<textarea id="result" rows="4" cols="50"></textarea>
</body>
</html>
I have a batch script below (which I was able to derive from Open a file in Visual Studio at a specific line number and How can I get the value of a registry key using a batch script? ).
#echo off
for /f "tokens=3*" %%x in ('reg query "HKLM\SOFTWARE\Microsoft\Window\CurrentVersion\App Paths\devenv.exe"') do set DEVENV="%%x %%y"
%DEVENV% /Command "Edit.Goto %1" "E:\Bat\Example\Sample\%2"
#echo off
I run the above batch script using a Javascript code given below, where the values of %1 and %2 are passed by this Javascript as a number (10) and a path (examples/helloWorld/helloWorld.cpp) as shown below
<html>
<head>
<script language="JavaScript" type="text/javascript">
MyObject = new ActiveXObject( "WScript.Shell" )
function Goto()
{ MyObject.Run("D:/GoToLine2.bat 10 examples/helloWorld/helloWorld.cpp") ;}
</script>
</head>
<body>
<h1>Run a Program</h1>
This script launches a bat file >> <p>
<button onclick="Goto()">Run BatFile</button>
</body>
</html>
My problem is that the registry key of "E:\Bat\Example\Sample" is HKLM\SOFTWARE\Wow6432Node\BI\Science\AB and I don't know how to get its value so that I need not have to pass the path as E:\Bat\Example\Sample\ in the batch file, but just get it from the registry and append the "%2" (which I get from the Javascript code - i.e. examples/helloWorld/helloWorld.cpp) to its value. I'm using a windows 7 64 bit PC.
#ECHO OFF
SETLOCAL
FOR /F "tokens=2*" %%A IN (
'REG QUERY "HKLM\SOFTWARE\Wow6432Node\BI\Science" /v AB'
) DO (set yourpath=%%B%2)
set yourpath=%yourpath:/=\%
ECHO %yourpath%
Should do the task. This is essentially a repeat of your earlier question for which you haven't yet accepted an answer.
I don't really get why you're bothering with a batch script anyway. Since you're already creating a WScript.Shell object, which is used both for executing a program and for reading from the registry, why not do the whole thing in JavaScript?
<html>
<head>
<script language="JavaScript" type="text/javascript">
function Goto(line, file) {
var osh = new ActiveXObject("WSH.Shell");
var devenv = osh.RegRead('HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\devenv.exe');
// is the file variable a full path? If not, get path from registry.
var batsample = /^\w\:\\/.test(file)
? file
: osh.RegRead('HKLM\\SOFTWARE\\Wow6432Node\\BI\\Science\\AB')
+ '\\' + file;
osh.Run(devenv + ' /Command "Edit.Goto ' + line + '" "'
+ batsample + '"');
}
</script>
</head>
<body>
<h3>Run a Program</h3>
<p>Click this to go to line 10 of helloWorld.cpp.
<button onclick="Goto(10, 'examples\\helloWorld\\helloWorld.cpp')">Run Editor</button>
</p>
<p>Click this to go to line 20 of helloWorld.cpp.
<button onclick="Goto(20, 'examples\\helloWorld\\helloWorld.cpp')">Run Editor</button>
</p>
<p>Click this to go to line <input type="text" id="line" value="10" />
of <input type="file" id="file" />.
<button
onclick="Goto(document.getElementById('line').value, document.getElementById('file').value)">Run Editor</button>
</p>
</body>
</html>
I need to create folder,copy it and delete.
So I've created several javascript functions - to get path to the folder, delete folder,create and copy folder.
But when I try to run it in google chrome I've got an exception
I thought it was problem with ActiveX. But in IE it doesn't work either.
<html>
<head>
<meta charset="utf-8">
<script type="text/javasript">
function onFolder(){
var ob = new ActiveXObject("Scripting.FileSystemObject");
var name = document.getElementById("idtextbox1").value;
var path = document.getElementById("idtextbox2").value;
var x = path + "\\" + name;
return x;
}
function onCreate(){
var ob = new ActiveXObject("Scripting.FileSystemObject");
var path = onFolder();
var x = ob.CreateFolder(path);
}
function onCopy(){
var ob = new ActiveXObject("Scripting.FileSystemObject");
var source = onFolder();
var dest = document.getElementById("idtextbox3").value;
ob.CopyFolder(source,dest + "\\");
}
function onDelete(){
var ob = new ActiveXObject("Scripting.FileSystemObject");
var folder = onFolder();
ob.DeleteFolder(folder);
}
</script>
</head>
<body>
Folder name<input type="text" id="idtextbox1">
<br>
Destination<input type="text" id="idtextbox2">
<br>
Copy destination<input type="text" id="idtextbox3">
<br>
<input type="button" id="idbutton1" value="Create" onClick="onCreate()">
<input type="button" id="idbutton2" value="Copy" onClick="onCopy()">
<input type="button" id="idbutton3" value="Delete" onClick="onDelete()">
</body>
</html>
What's the problem? Is it ActiveX? Because I think javascript functions are correct.
The big problem is that you are using chrome Chrome. ActiveX only works in IE because it is a non-standard function. And for what you are trying to do, the security level has to be on low which is very unconventional. JavaScript is just not a good language to be trying to access or update a computers file system.