How do I let a user paste an image on a webpage? - javascript

I want to give the user possibility to paste an image into a webform. I don't need to display the image, all I need is the image's location.
I know it's possible because the guys at CKEditor(and other editors) are doing it.
If you go here, http://ckeditor.com/demo and paste an image you copied and then right click on it and go to image properties you'll see they have the image's address.
How can this be done?
Thanks

It is not possible because giving a browser the possibility to access local files, which have not been added to be uploaded explicitly by the user, opens a variety of very dangerous security holes that would certainly be super-exploited by hackers.
A good solution would be to give the posibility to upload using Ajax and link the images in the document once they are available in the server.
Take a look at “Sending files using a FormData object” part of the Using XMLHttpRequest document at Mozilla Developer Network.

Related

Display PDF like on web

I am trying to display PDF file on the web without download option and copy option.
Then I found this https://books.google.co.in/books?id=kwBvDwAAQBAJ&printsec=frontcover&source=gbs_ge_summary_r&cad=0#v=onepage&q&f=false
Can you tell me how can I achieve this on my website?
What mplungjan said in his comment is correct. Anything that is put on the web can be copied one way or another. It appears that the google site you linked to is just showing an image of each page (see https://books.google.co.in/books/content?id=kwBvDwAAQBAJ&pg=PP1&img=1&zoom=3&hl=en&sig=ACfU3U0s8V3HjcApLeNwIGStMQlzZFaotA) with transparent pixels over each image to make it so you can't right-click to save the image. But it's easy to see what they're doing by viewing the source in the inspector.
If you don't want your users to be able to download the entire file, you could break it up into multiple small files (or images, like google is doing in your link) that would make it a little harder for them to get the files. But you can't really stop them from downloading anything.

File information while HOVERING over element

I'm working on a webpage for managing files. For a feature I need to know the file name when hovering a file over a element. It's important to get this information while HOVERING not when "dropping" the file.
I created a JSFiddle with the setup. When you hover a file over the marked div you constantly get some information about the filetype.
You can get the dataTransfer from the hovering event
let transfer = event.dataTransfer;
The item property contains the file's MIME type.
transfer.items
However, you don't get full information about the file (name, size, ...).
transfer.files
When dropping the file i get full informaton about the file
transfer.files.lenght //Equal to amount of files dropped
I read in a few old posts (< 2008) that this might be a security reason, which I don't understand. There is basically no difference between hovering a file or dropping a file (apart from releasing your LMB).
Thanks your help :)
Without the protection system, it would mean a website could track everything you drag over it. Let's say you want to move a file from your finder to someplace else and your browser is in the path. Or you drag some text from word to some other app, and you happen to go even for just a short while over your browser window. Your website could access all these contents, without the user wanting to interact with it.
The mouse release is a voluntary action from the user, making it clear that he wants to transfer whichever data he is dragging to the specific web page.
Note that if you control the dragstart, you can get the info. But if your page is not the actual agent beginning the drag, then you can not assume until the item is dropped, that the user wants the content visible to your page.

Disable toolbar in PDF Web View Element to disable Download and Print

My issue is that I have to deploy a local server (without internet), so I cannot use Google Doc Viewer in this case. All I want is to restrict the user from download or printing the document. I have tried hiding or removing the toolbar in JS but it is not working out.
You may be able to disable the toolbar somehow, but that isn't good enough to keep users from downloading or printing it anyway, and nothing you can do will be. If a person can see something, they can copy it, no matter what you try to do to stop them (and all trying will do is inconvenience legitimate users). Previous similar questions:
How to prevent downloading images and video files from my website?
disable downloading of image from a html page
https://graphicdesign.stackexchange.com/questions/39462/is-it-possible-to-prevent-download-of-images-when-designing-a-website
Although those talk about images, the exact same reasoning applies to PDFs.

Is it possible to serve up a different file than the intended one to be downloaded via JavaScript?

At work they want to do this to prevent people from downloading images easily from our site. They won't go the disable right click option, so they want to do what Flickr is doing:
http://www.flickr.com/photos/scg/12332332454/sizes/l/
If you right click and try to download that image it downloads the entire html page instead. Can this be done via JS or is it something handled by the server?
I know all this goes against usability and doesn't actually prevent people from ripping off images but it's what the ticket I'm assigned asks for.

Prevent saving images from website (save whole page)

Is there a way to prevent users from saving images when they do a save as?
I have already disabled right click in the pages using javascript as well as adding the following header:
<meta http-equiv="imagetoolbar" content="no" />
But if I go for example in OPERA and do page -> save as -> html file with images all the images will get saved. IS there a way to counter this?!
They will always be saved. Your browser caches images locally anyway, so they'll always be downloaded to a users machine and if they wanted to take them, they would.
The only way to stop images from being saved is don't put them on the internet.
No, there is not. If an HTTP client can download it, it can save it. It is a futile effort to try and counter this.
Edit: Also, I'd like to point out that most browsers allow the user to forcefully (re-)enable the right-click menu on evil websites who try and take that freedom away from them.
No, there is always a way for users to get your images. If you dont want your images reused consider watermarking them if this is appropriate or branding them with the company logo.
Disabling right click will just annoy the hell out of users who probably wouldnt steal your images anyway, and be a minor inconvenience to those who would.
No right click? Just screenshot the page, maybe view source and go directly to the image file, etc etc.
Just out of curiosity, why do you even want to do this?
You can do what the author of this page did with a picture of Homer Simpson. Look ma, no <img>!

Categories