Local html file on CD can open links with default program - javascript

For example I have a html file :
test
On chrome - when clicked the file downloaded to default directory
On IE - when clicked asks to open or download
how somehow when clicked, automatically open it with default program in windows

I dont have any references but i think youre not in controll of that behaviour. You can probably as well configure chrome the way it asks you before downloading and vice a verse configure IE to not ask but download the files in a certain directory.
Maybe there is a possiblity to have a java script code running on page load that initiates a download directly without any notification to the user but that wont run in any cases as well (since youre not in controll if someone switches off java script).

Related

png files failing to load when opening html file directly, but they load when opening from webstorm

I've been working on a game in javascript for my CS course. When I open the document by hitting run in Webstorm, it loads the game correctly, however when I just try opening the html file from Finder, the webpage opens but none of the png files I'm using for the sprites load. I opened Inspect Element in google chrome, and the javascript files loaded correctly but all the png files listed as canceled. This doesnt happen when the game is run from webstorm (when I run it from webstorm, all image files load properly).
When the game is opened directly from an html file (that's when I have the problem), chrome lists the path of the html document as the webaddress, although when opened from webstorm, it lists http://localhost:63342/CS%20Week%2010/CS105_Jessica.Davis_DogGame.html?_ijt=tmrr2fndgac82h07hlvt101gi4
How can I get around this issue so that when opening the html file from Finder it loads everything correctly? All image files are in the same directory as the html file.
Because of browsers security, loading files like this might not work from a url starting with file://
What webstorm is probably is making a local web server so that instead of saying file:// you could say http://. if any website was able to load images from file:// then any webpage you visit would have been able to search for any file on your computer and send it over the internet without your consent so browser often have these settings on. So you'd need a server. If you are working on your computer, you could make a local server just like webstorm and host your own files there. or host it on another service like github pages or codepen.
Now since all images are in the same directory, make sure that every time you call loadImage you use the images name and extension instead of saying /User/user/whatever_other_directory_you_have_it_under/image.png.
Once you did that you can make a local web server for the project. To make a local server, open Terminal (an application under utilities, you could spotlight search for it as well) and type cd, drag your project folder and drop it over terminal, and hit enter. Then type python -m SimpleHTTPServer and wait till it says something like Serving HTTP on 0.0.0.0 port 8000 .... Then taking the 0.0.0.0 and the 8000 you see in the example (yours may or may not be the same) go to your browser and type http://0.0.0.0:8000 (replacing the digits with whatever you got, not this link doesn't work until you do that)
Images should load alright. If you need to stop the server you can go back to terminal and hit control+C.
Note that when presenting your p5 sketch, no one else would be able to see the website on their computers if you make your local server. The local server is secluded to the device that is running it (although if their making their own local server and have your project files it should work just fine).
If you want the website hosted so that you could share a link with anybody in the world you could use codepen or github pages. If you go to codepen.io it should be self-explanatory although you'd have to upload your images to some image hosting site like tumblr or something and add the URL source of those images to codepen or you could put everything into github for even better results!
To use github pages you'd need to make a github account (preferably with your username being whatever you want your page to be named). Make a repository named insert_username_here.github.io. add your files to the repository (make sure to try to keep all sub directories and folder exactly as they are from your project folder). After a minute or two go to http://insert_username_here.github.io to admire your brand new hosted webpage!

Why is control of flow not reaching to the file according to file path I am providing

While automating the upload file feature in selenium using Java, the control is not going to the file according to the file path I have provided. Why is the control not reaching to the file properly?
My code
uploadWebElement.click();
(new Actions(DriverConfiguration.driver())).sendKeys(new CharSequence[]{filePath, Keys.ENTER}).perform();
Error
The problem is when I clicked for browse, it opens the desktop folder and the one where I saved the file, is not reaching through this.
if upload popup is windows/OS one then selenium can't work, if the popup up is related to browser then sendkeys will work to upload the file.
Point is actions bit not working in present gecko if you are using firefox.
For handling windows popup, you can try Robot class in java or AutoIT tool etc..

Cross Browser Download .Bat Files

I am building a web tool that is meant to be used internally by the company I am currently working for. The tool needs to generate a bat file and run it on the user's computer from the browser. Creating the bat file works fine, the issue lies when trying to run the bat file. The bat files are on the network of the company, for the sake of the question lets say that
batpath = \\domain\path\to\the\file.bat
At first, I tried to use window.open('file:' + batpath) in JavaScript, which worked in Internet Explorer, but would only open a blank tab in Chrome. My work around to this was to display the folder where the bat file was and prompt the user to run their file there in Windows Explorer manually, but I was asked to make the whole process in the browser with now Windows Explorer.
The next thing I tried was to generate an anchor tag with the download attribute to download the bat file manually
The anchor tag would be <a href="file://domain\path\to\the\file.bat" download>runbat</a>
That also works fine in Internet Explorer, but does not do anything at all in chrome.
Is what I am trying to do even possible? If so, how would I get this to work?
I would create a URL protocol on the machine and have it execute the bat file.
Check this link: https://msdn.microsoft.com/en-us/library/aa767914.aspx
Basically it's work like so:
Create the protocol and call CMD.EXE and pass in the bat file path
Call the protocol by generating the links "batrunner:file-path-to-bat.bat"
This should work on all browsers. You'd want to be careful doing this though and possible build a custom application to call the bat file for security reasons.

Changes to JavaScript File Not Showing on Chrome

I am trying to experiment with a website by changing some of its javascript code. The steps that I am following are:
Open up Chrome Dev Tools and then navigate to the sources tab.
Add a folder to the workplace.
Right click on the javascript file that I want to alter and select Map to File System Resource.
Select the matching javascript file in the new folder that I added.
However, when I make changes to the javascript file in the new folder and reload the webpage, the changes do not appear. The changes are also not present when I open up dev tools and look at the javascript file. Am I missing something ?
refresh the cache when you reload with CMD+Shift+R if you're on Mac. On windows i think it's Ctrl+Shift+R

Google Chrome extension - download, move and delete files

I am trying o make app for my work (will be used only in my office) and among other things I need way to download file (it will be always one ODT and one txt document which will be initiated by clicking on button by user, on specific page - standard download) from our local server. Those two files are created on server and then sent to download to user which requested it, so that part is simple as any other web page which offers you download.
But after download is finished I need somehow:
1) automatically open ODT (openOffice writer) file, so user can continue editing it. What will happen next is not important...
2) automatically move TXT file to specific folder on users disk (this is needed because that specific folder is monitored by our special printer and whenever printer detects file in that folder it automatically starts printing). Setting default chrome download folder as that monitored folder is not options - so I NEED to move TXT file automatically after download to that monitored folder.
3) After first two actions are finished I need to clean default download folder (foldere where chrome downloads by default) because it would be full of those files and they are not needed anymore.
Now, it would be great if I could accomplish it just with javascript but as I know there is no way to manipulate files on local system without displaying dialog to user - so this is not option.
I figure it out that this part could be done by chrome extension, which is acceptable solution because this application will be used only in my office. But I am not sure how and if it is really possible to accomplish what I want so I need your help.
P.S.
It is important that after user click "Download" on page to download ODT and TXT file, there is no other windows, dialog and other "questions" by browser but everything after that should go automatically.
Thank you!
Yes, you can do those tasks with chrome.downloads API, as long as you can accept a subfolder of the Downloads folder as a target for your printer. You cannot download in an arbitrary folder, I'm afraid.
After a download you initiated with chrome.downloads.download finishes, you can initiate opening it with chrome.downloads.open(downloadId).
You can initiate a download into a subfolder by supplying a relative path to chrome.downloads.download (note the / slash instead of \): printout/file.txt.
You can remember the download id's and clean up afterwards with chrome.downloads.removeFile(downloadId).
Please take note of the permissions you need to add, they are quite fine-grained for this API.

Categories

Resources