How to read a Bookmarklet from java? - javascript

There is a Javascript that needs to be executed after hitting the page in the browser. This javascript runs only when it is stored as a bookmark in the browser. My task is to execute this javascript that is stored in the bookmark in the browser using a java code.
On Googling, I find that the URL can be bookmarked via a java code. But I dont find how to read the bookmark. Please suggest how can I read it through java code.
Thanks in advance!

There is an answer which said that is impossible to do it unless you do a browser extension:
Get browser bookmarks via javascript
Although another answer talks about upload the browser bookmark file and read it in javascript :
Inside the "...\Chrome\User Data\Default\" directory are two files. "Bookmarks", and "Bookmarks.bak". One is for your current bookmarks, and the other one (with the .bak extension) signifies that it is a bookmarks backup, if anything goes wrong. Bookmarks.bak gets overwritten every time you close Chrome.
Bookmarks in Chrome exist as a virtual filesystem. Meaning, that all
your bookmarks are really just stored in one file, but appear as an
actual filesystem inside Chrome.
You only have to copy that file, and back it up somewhere. And if you
want to recovery your bookmarks, simply copy/paste the "Bookmarks"
file you backed-up, back in to the directory you took it from.
Chrome must be closed prior to doing this.
Hope this helps.
(and btw, try opening the "Bookmarks" file with a text editor like
Notepad =])
Location of chrome bookmarks

Related

Open a file for reading and writing in JavaScript

I would like a way of doing this:
User selects client-side file from prompt.
Browser passes file reference to client-side code.
Code can read and write to the file indefinitely without any more user interaction.
It needs to run in the browser.
(This is not a duplicate of How do I open a file stream in javascript?; that question is over 5 years old and the file APIs have changed a lot since then. Also, it doesn't keep the file open.)
I dont think you can open a file w/o re-prompting the user unless your code is privileged in the browser (like a browser extension). I have found an api that let you do exactly what you want. but you need privileges to use it.

Using a Chrome extension, how to get page source and save to a local file?

I'm new to Chrome extensions, and don't need a lot from an extension, so I haven't studied JS or the HTML5 Chrome API in great detail (however, I do know HTML). Other pages in Stackoverflow were not quite what I was looking for.
Basically, I am writing a program that will take HTML page source data and parse certain information out of it for use with another program. What I need to be able to do is use a Chrome extension to get the source of a web page, then save it to a local HTML file for the program to use.
I'm using most of the extension source code from this thread: Getting the source HTML of the current page from chrome extension
This works very well, except I need the source to go to a local file and not in the popup. In the popup, I'm going to add in a message like "File saved" along with a button to open the external program (if that's even possible). Any help or a step in the right direction would be greatly appreciated.

how to know browser download location programatically

I have a webpage, that downloads a file,
now the requirement is to show a alert where the downloaded file has been stored.
Is it possible to get the download folder location of a browser through any of browser properties(navigator,window,location etc). Please help.
Thanks in advance
Nope, it is not possible.
Paths, and the whole HDD are beyond browser sandbox, you can't even got the choosen path from "Pick file to upload" (<input type="file"...) buttons.
If it's a normal webpage then forget about it as #ProblemFactory says. But if it's a webapp for closed group of users and you can enforce to use a specific browser then you can achieve this goal by creating a browser extension. At least I know it's possible in Firefox.
And here is the documentation of API https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Downloads.jsm/Download
The target property of the Download object holds the path to the file.
As you said that you are using IE9, I assume that the choice of the browser is up to you.

Is it possible to open a file from a shared folder outside the browser

We have a file handling ASP.Net web control used in intranet web applications, that currently uses ActiveX to handle file check-outs, and check-ins. Works fine, in IE&Win.
But now we are trying to get rid of ActiveX & IE only behavior...
If a file is checked out, it is copied to file share, with access right limited to the checking-out user.
Using a hidden iframe, and setting the src of the iframe to something like "file:////file_share/dictionary/users_stuff/someDoc.doc", an open/download dialog is shown, so the user can open and edit the shared file in Word, Excel, etc directly from the file share.
Works fine for file types browsers can't handle themselves.
But for file types like txt, images, html the browser simply loads the file to the iframe, or opens the file, if the user is given a link. And the user can't edit the file without manually launching the appropriate application and copying the url. Showing the users a "Copy this url to your preferred application, and try to edit it" would not be really user friendly...
My question is: is it possible to get the browser (without ActiveX, IE...) to pass the link to the OS, or show a "What do you want to do with this file" dialog of some sort?
If not, what and how could be achieved?
The closest I could come up with is this thread:
https://stackoverflow.com/a/1394725/1195927
#Red says no (and the original poster agrees) BUT #Daan seems to have a solution.
I have not tested, so YMMV.
If a javascript/html solution is not found, I may have an ugly hack for you . . .
See my post here: Launching a Downloadable Link

Looking for doc on why IE "yellow bar" shows when opening a HTML file that contains JavaScript

I have a site, from which you can download an HTML file. This HTML file contains a form with hidden fields, which is right away posted back to the site using JavaScript. This is a way of allowing users to download to their own machine data that they edit on the site.
On some machines, you get an IE "yellow bar" when trying to open the file you saved. The "yellow bar" in IE is warning that the HTML is trying to run an Active X (which it is not, there is only JavaScript doing a submit() on a form). However if you receive the exact same HTML file by email, save it, and open it, you don't have this problem. (It looks like IE is putting some more constraint on what can be done in a HTML file you saved from web site.)
My question is: where can I find documentation on this IE security mechanism, and possibly how can I get around it?
Alex
The yellow bar is because your page is executing in the Local Machine security zone in IE. On different machines, the Local Machine security zone might be configured in different ways, so you can see the yellow bar on some machines and not see it on other machines.
To learn more about the IE's URL Security Zones, you can start reading here: http://msdn.microsoft.com/en-us/library/ms537183.aspx
Look here for details on the MOTW - Mark Of The Web
If you add this to your locally served pages, IE will not show the yellow bar.
http://msdn.microsoft.com/en-us/library/ms537628(VS.85).aspx
I am not usre about any specific documnet, but if you open the properties for the file in windows explorer on the general tab is the file blocked? if so click unblock and try again and see if you gte the same issue. This is typical security for files downloaded fom the internet.
Other than that i am afraid i dont know what else to suggest.
I don't 100% follow what your JavaScript is submitting to, but if you're submitting back to the original site from the downloaded copy you'll have a problem using JavaScript as all browsers treat cross-domain JavaScript as a security violation.
JavaScript isn't allowed to read or write to any site not on the current domain
As Franci had said it is becaue you are in the local machine security context and this allows scripts to create objects and execute code that could do harm to your PC. For example you can create a File System Object and perform tasks that an untrusted page shouldn't perform generally because it could be malicious in nature.
Have you tried changing the file name from yourname.html to yourname.hta to see if the security problem goes away?
More on HTML Applications (.HTA files): http://msdn.microsoft.com/en-us/library/ms536496%28VS.85%29.aspx

Categories