I own a local PHP point of Sale, using wampp as my web-server (Win7). What I'm looking for is to find a way to open the Flash Drive E as we normally do by visiting My Computer - > USB Flash E: ... but using JavaScript.
I have found this code, which works perfectly as needed... But this only works on IE, I'm using Google Chrome as my POS browser but what Chrome does... Opens up a blank window!
Here is the code:
<script>
function CallMe()
{
window.open("file://PCNAME/E$");
}
</script>
<html>
<input type="button" onClick="CallMe()" value="Open USB" />
</html>
Is there an alternative way to open USB Drive E? Maybe by using PHP?
You could allow the user to navigate their filesystem from the browser using:
<input type="file" />
You can't specify a default location nor can the browser open it automatically, however.
window.open("file:///" + yourLocalOrNetworkPath);
Related
I have an HTML page that contains a button says "Open Popup". Once this button is clicked, a popup window opens (using window.open).
The new popup window is an HTML page that contains a simple input filed and a submit button. Once the submit button is clicked, the popup window should close, and the text that's just been typed in the input field should now be displayed in the parent window.
I've tried doing it using opener.document.getElementById. It works perfectly in Firefox, but not in Chrome.
This is the code of my parent page (parent.html):
<!DOCTYPE html>
<html>
<body>
<button type="button" onclick="openPopup()">Open Popup</button>
<p id="result"></p>
<script type="text/javascript">
function openPopup() {
var popupWindow = window.open('popup.html', '', 'width=300, height=200');
}
</script>
</body>
</html>
And this is the code of my popup (popup.html):
<!DOCTYPE html>
<html>
<body>
<input type="text" id="userText" placeholder="Please enter some text">
<button type="button" onclick="submitText()">Submit!</button>
<script type="text/javascript">
function submitText() {
opener.document.getElementById('result').innerHTML = 'The text you\'ve entered is: ' + document.getElementById('userText').value;
self.close();
}
</script>
</body>
</html>
Note: Both parent and popup files are located in my desktop.
As mention, it works in Firefox, but not in Chrome. When I click the "Submit!" button in Chrome, nothing happens, and the following error shows up in the console:
Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.
I spent hours trying to find help online, but I still can't make Chrome pass data from popup window to parent page (which both are, as mentioned, located in my desktop, i.e. in the same directory).
Thanks in advance.
What you are encountering is a security feature of Chrome that is applying a web security standard called CORS (Cross-Origin Request Specification). It's meant to prevent one website from accessing another (because this is a common technique to try and trick people into giving up personal information), unless both the pages originate from the same domain. For example, http://domainA.com shouldn't be able to communicate with http://domainB.com by default. In situations were this is a legitimate need, server configuration is required to allow it.
Because you are running your tests from your desktop (without a web server) no domain information is present and Chrome thinks you are making a Cross-Origin Request.
If you run your files from a web server (over http or https), it will work.
There are many free web servers available for you to set up on your local machine and many development tools incorporate their own web servers. For example, VS code and Visual Studio are both free and have web servers included.
I have a local file a.html as follows, which can be launched by https://localhost/a.html. by clicking on Open b, it can open another file b.html, then by Send button, it could send data by postMessage:
<html>
<body>
<p onclick="openWindow()">Open b</p>
<form>
<input type="button" value="Send">
</form>
<script>
function openWindow() {
var popup = window.open("https://localhost/b.html", "popup", "width=200, height=200");
// var popup = window.open("https://localhost:3000/#/new", "popup", "width=1000, height=1000");
var button = document.querySelector("form input[type=button]");
button.onclick = function(e) {
e.preventDefault();
e.stopPropagation();
popup.postMessage("hi, how are you?", popup.location.href);
}
}
</script>
</body>
</html>
Now, rather than opening https://localhost/b.html, I want to open a page https://localhost:3000/#/new served by a local application. So I uncomment the line var popup = window.open("https://localhost:3000/#/new", "popup", "width=1000, height=1000");. Then it raises an error while opening it:
Uncaught DOMException: Blocked a frame with origin "https://localhost" from accessing a cross-origin frame.
at HTMLInputElement.button.onclick (https://localhost/a.html:20:49)
So it seems that https://localhost/ and https://localhost:3000/ are considered as cross-origin.
Does anyone have any solution or workaround to make https://localhost/a.html open https://localhost:3000/#/new?
Edit 1: I use Mac. Actually when going to production, everything will be put under a same domain www.myexample.com, which has static files like a.html and runs a server. I just want to have an easy solution for development in localhost in Mac.
Edit 2: A limitation is that, I have to open a.html by https://localhost/a.html; I am NOT allowed to use http or serve it as a static file (ie, https://localhost:3000/a.html).
You have mentioned you're using MEAN stack, so I assume you are using ExpressJS.
It's possible to serve static (for development): see http://expressjs.com/en/starter/static-files.html
Do NOT use https on localhost... It makes nothing more secure and just add an unneeded self-signed certificate.
For a more generic solution, nginx can be used to serve static files and pass other paths to the backend.
One solution is open Chrome in a terminal with some special arguments:
open -a Google\ Chrome --args --disable-web-security --user-data-dir=/Users/SoftTimur/Desktop/user-data-dir
I have also tried some Chrome add-ins, which did NOT work for my tests.
It will be great if we have a solution (eg, some setting) without having to open Chrome from a terminal each time...
is there any way to use javascript to open a link in an external program and not(!) in the web browser?
Background: From CRM2015 on-premise i want to open a Mail in Lotus Notes.
script:
<html>
<body>
<p onclick="myFunction()">Click me</p>
<script>
function myFunction() {
window.open("notes:///server/file");
}
</script>
</body>
</html>
What happens: the mail opens in Lotus Notes -> good
But also an additional tab in IE11 occurs, blank page and link in address bar -> bad
What should happen: mail will open in Lotus Notes but no additional tab or windows in IE11.
Is there any way to solve my issue?
Thanks a lot for you help and have a great weekend!
If you want to navigate to an external protocol via JS, do it the same way you'd navigate to a HTTP URL:
function goSomewhere() {
window.location = "notes:///server/file";
}
Sane browsers should 1. stay on the same page, and 2. launch the external program (emphasis on should and no guarantees on insane browsers - e.g. IE8 and below).
In our web application we need to find out if a Custom URL Protocol Handler is registered or not in windows 10 machine using javascript with Windows 10 EDGE Browser.
If the Custom URL Protocol Handler is not registered in the windows 10 machine we will ask the user to download our desktop standalone app.
If registered we will start our desktop standalone app using the registered Custom URL Protocol Handler.
Since EDGE is a new browser the solutions provided by other users in the internet are not working.
Links I referred that are not working for me in EDGE browser:
https://gist.github.com/keyvanfatehi/f2f521c654bab106fdf9
Please help me out,
Thank you
Maybe this workaround helps:
Whenever you navigate to an unkown protocol with MS Edge, Windows asks the user about the app to handle this protocol. You could just navigate to your protocol and display a message with some information about what to do if the tool does not open. Something like this (sorry for the German screenshot):
<div id="toolBox">
<p id="toolBoxText"></p>
<input type="button" id="toolButton" onclick="openTool()" value="Start tool" />
</div>
<script type="text/javascript">
function openTool(){
window.location = 'myprotocol://command/';
document.getElementById("toolButton").value = "Try again";
document.getElementById("toolBoxText").innerHTML = "Thank you for using our tool. If the tool did not open successfully, please first download and install the tool <a href='download/'>here</a> and then try again."
}
</script>
I save this file as test.html and when I opened this file in IE, I am getting Information Bar for ActiveX Controls, Is there any way we can disable this thing using javascript code or jQuery code?
<html>
<body>
<h1>My First Web Page</h1>
<script type="text/javascript">
if(navigator.appName == "Microsoft Internet Explorer")
{
window.location = "http://www.google.com/"
}
else
{
window.location = "http://www.yahoo.com/"
}
</script>
</body>
</html>
And I just wanted to make sure, as I am running locally on my box so that is the reason it is showing ActiveX control Information bar? And Once I upload this file to a remote server and access it from there then this active x bar will not appear??
But is there any way programmatically to disable this information bar? Any suggestions will be appreciated.
Use Mark of the Web (MOTW). We can disable the ActiveX controls warning by putting following code before the opening html tag:
<!-- saved from url=(0014)about:internet -->
<html>
<body>
......
</body>
</html>
The above code is call “Mark of the Web (MOTW)”, this is a feature of Windows Internet Explorer that enhances security by enabling Internet Explorer to force Web pages to run in the security zone of the location the page was saved from
The Information Bar you're seeing is unrelated to ActiveX (even though it might say "ActiveX"). It's simply telling you that a IE isn't running scripts on a local file, a security precaution.
Yes, when accessed via HTTP, the warning won't appear.
There's no way to programmatic disable it because (1) your code isn't running in the first place; and (2) doing so would circumvent the security restriction that this is meant to be. Use the MOTW.
If you just want pages to work on your machine, go to Tools, Internet Options, Advanced, and check Allow active content to run in files on My Computer. I'd only enable this option while developing, however.