🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.javascript
Article #49290

Firefox, security error, toDataURL()

#49290
From: MJM
Date: Tue, 08 Sep 2009 09:25
49 lines
2593 bytes
Dzień dobry,

Poniższy przykładowy kod działa w Google Chrome i Opera, Firefox natomiast wyrzuca błąd:

Error: uncaught exception: [Exception... "Security error"  code: "1000" nsresult: "0x805303e8 (NS_ERROR_DOM_SECURITY_ERR)" 
location: ...

Wygląda na to, że FF się nie podoba moja próba zapisania do obrazka danych z canvasa img2.src = canvas.toDataURL();
Czy ktoś może wskazać gdzie popełniłem błąd albo podpowiedzieć jakieś obejście problemu?

Pozdrawiam
Michał Mierzwa

-----------------------PRZYKŁADOWY KOD--------------------------------
function rysuj(pimg) {
  var canvas = document.createElement("canvas");
  canvas.style.position = "absolute";
  canvas.style.left = "100px";
  canvas.style.top = "100px";
  alert(pimg.height);
  var r = Math.sqrt(2* pimg.width * pimg.width);
  alert(r);
  canvas.setAttribute("width", r);
  canvas.setAttribute("height", r);
  canvas.style.border = "1px solid blue";
  document.body.appendChild(canvas);
  var ctx = canvas.getContext('2d');
  var angle = 45;
  var rad = angle * Math.PI /180;
  ctx.rotate(rad);
  ctx.drawImage(pimg,46*Math.cos(rad),-46*Math.sin(rad),66,66);

//TUTAJ WYRZUCA BŁAD!!!?
  var img2 = document.createElement("img");
//ALE PRZYCZYNA WYDAJE SIE BYC toDataURL()
  img2.src = canvas.toDataURL();

  document.body.appendChild(img2);
  var img3 = document.createElement("img");
  img3.src = "1.jpg";
  document.body.appendChild(img3);
}

function laduj() {
  var img5 = document.createElement("img");
  img5.src = "1.jpg";
  setTimeout(function(){rysuj(img5);},100);
}
laduj(); 
Technical Details
Message-ID: <h857tm$bul$1@mx1.internetia.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!feed.news.interia.pl!news.nask.pl!news.nask.org.pl!news.internetia.pl!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!feed.news.interia.pl!news.nask.pl!news.nask.org.pl!news.internetia.pl!not-for-mail
From: "MJM" <oj.moze@lepiej.nie.pl>
Newsgroups: pl.comp.lang.javascript
Subject: Firefox, security error, toDataURL()
Date: Tue, 8 Sep 2009 11:25:00 +0200
Organization: Netia S.A.
Lines: 51
Message-ID: <h857tm$bul$1@mx1.internetia.pl>
NNTP-Posting-Host: 77-252-84-78.ip.netia.com.pl
X-Trace: mx1.internetia.pl 1252401910 12245 77.252.84.78 (8 Sep 2009 09:25:10 GMT)
X-Complaints-To: abuse@inetia.pl
NNTP-Posting-Date: Tue, 8 Sep 2009 09:25:10 +0000 (UTC)
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
X-RFC2646: Format=Flowed; Original
X-Tech-Contact: usenet@internetia.pl
X-Newsreader: Microsoft Outlook Express 6.00.2900.5843
X-Priority: 3
X-Server-Info: http://www.internetia.pl/news/
X-MSMail-Priority: Normal
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit