简体   繁体   中英

How to use Javascript to automatically save the images on the website with Chrome extension?

Method 1.

-- use the iframe.

  1. Create an iframe, when pressing the save button.
  2. set the "src" property to a url of an image on the website.
  3. invoke the iframe.document.execommand. //useless, it seems the execommand is only for IE.

Method 2.

-- use a canvas

  1. Create a canvas
  2. Draw the image into the canvas.
  3. invoke toDataURL // Security Error

{
  "name" : "...",
  "version" : "1",
  "description" : ".....",
  "content_scripts" : [{
    "matches" : ["http://domain/p/*"],
    "js" : ["i.js"],
    "css" : ["i.css"]
  }],
  "permissions": [
    "http://*.domain.com/*"
  ]
}

Is there any other way to handle the problem?

It's a very old question, but since then chrome.downloads API became a thing.

It's sufficient to extract URLs of all the images you're interested in, and pass them to chrome.downloads.download . Please note that you may need to set a referrer in some rare cases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM