亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
Attributes accesskey (attribute) class (attribute) contenteditable (attribute) contextmenu (attribute) data-* (attribute) dir (attribute) draggable (attribute) dropzone (attribute) Global attributes hidden (attribute) id (attribute) itemid (attribute) itemprop (attribute) itemref (attribute) itemscope (attribute) itemtype (attribute) lang (attribute) slot (attribute) spellcheck (attribute) style (attribute) tabindex (attribute) title (attribute) translate (attribute) Elements a abbr address area article aside audio b base bdi bdo blockquote body br button canvas caption cite code col colgroup data datalist dd del details dfn dialog div dl dt em embed fieldset figcaption figure footer form h1 head header hr html i iframe img input input type="button" input type="checkbox" input type="color" input type="date" input type="datetime"-local input type="email" input type="file" input type="hidden" input type="image" input type="month" input type="number" input type="password" input type="radio" input type="range" input type="reset" input type="search" input type="submit" input type="tel" input type="text" input type="time" input type="url" input type="week" ins kbd label legend li link main map mark menu menuitem meta meter nav noscript object ol optgroup option output p param picture pre progress q rp rt rtc ruby s samp script section select slot small source span strong style sub summary sup table tbody td template textarea tfoot th thead time title tr track u ul var video wbr Miscellaneous Attributes Block-level elements CORS enabled image CORS settings attributes Element Inline elements Kinds of HTML content Link types Microdata Optimizing your pages for speculative parsing Preloading content Reference Supported media formats Using the application cache Obsolete acronym applet basefont big blink center command content dir element font frame frameset hgroup image input type="datetime" isindex keygen listing marquee nextid noframes plaintext strike tt xmp
characters

HTML 規(guī)范中圖片有一個(gè)crossorigin屬性,結(jié)合合適的CORS響應(yīng)頭,就可以實(shí)現(xiàn)在畫布中使用跨域<img>元素的圖像。

查看 CORS settings attributes 來了解更多crossorigin屬性的用法。

什么是“被污染”的 canvas?

盡管不通過 CORS 就可以在畫布中使用圖片,但是這會(huì)污染畫布。一旦畫布被污染,你就無法讀取其數(shù)據(jù)。例如,你不能再使用畫布的 toBlob()toDataURL() 或 getImageData() 方法,調(diào)用它們會(huì)拋出安全錯(cuò)誤。

這種機(jī)制可以避免未經(jīng)許可拉取遠(yuǎn)程網(wǎng)站信息而導(dǎo)致的用戶隱私泄露。

示例: 存儲(chǔ)一張外部域中的圖片

你必須有一個(gè)可以對(duì)圖片響應(yīng)正確Access-Control-Allow-Origin響應(yīng)頭的服務(wù)器。你可以使用以下片段 (來自 HTML5 Boilerplate Apache server configs) 實(shí)現(xiàn)正確響應(yīng)頭。

<IfModule mod_setenvif.c>    <IfModule mod_headers.c>        <FilesMatch "\.(cur|gif|ico|jpe?g|png|svgz?|webp)$">
            SetEnvIf Origin ":" IS_CORS
            Header set Access-Control-Allow-Origin "*" env=IS_CORS        </FilesMatch>    </IfModule></IfModule>

配置完畢后,你就可以將這些圖片保存到DOM 存儲(chǔ)中了,就像這些圖片在你自己域名之下一樣。

var img = new Image,
    canvas = document.createElement("canvas"),
    ctx = canvas.getContext("2d"),
    src = "http://example.com/image"; // insert image url hereimg.crossOrigin = "Anonymous";img.onload = function() {
    canvas.width = img.width;
    canvas.height = img.height;
    ctx.drawImage( img, 0, 0 );
    localStorage.setItem( "savedImageData", canvas.toDataURL("image/png") );}img.src = src;// make sure the load event fires for cached images tooif ( img.complete || img.complete === undefined ) {
    img.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
    img.src = src;}

瀏覽器兼容性

Feature

Chrome

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

13

8

No support

No support

?

Feature

Android

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

?

?

?

?

?

Previous article: Next article: