canvas 导出海报报 SecurityError 跨域图片不设 CORS 头怎么改

陆零云 29 0
活动海报页要把商品图、二维码和标题拼成一张图给用户保存,导出走 canvas.toDataURL('image/png')。上线第二天运营反馈部分用户点了没反应,控制台一行红字:Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported. 同源的商品图没事,只有 CDN 那批图会把画布画脏...

跨域 iframe 读 scrollHeight:SecurityError 挡住了高度怎么自适应

陆零云 37 0
父页面嵌了一个跨域的活动页 iframe,想按内容高度自适应。父页面在 onload 里读 iframe.contentDocument.documentElement.scrollHeight,Chrome 120 控制台直接抛 Uncaught DOMException: Blocked a frame with origin "https://a.example" from accessing a cross-origin frame。 试过把 if...

前后端分离后 POST 请求报 403,OPTIONS 预检怎么放行

陆零云 46 0
现象:GET 正常,POST 一律失败 前后端分开部署后,浏览器里 GET 请求能拿到数据,一旦提交 JSON 就报跨域错误。Network 面板里能看到一条 OPTIONS 请求返回 403,后面真正的 POST 根本没发出去。用 Postman 直接调接口却是 200。 原因:预检请求被当成非法方法拦了 当请求带自定义头、使用 Content-Type: application/json 或跨域携带凭证时,浏览器会先发一条 OPTIONS 预检,询问...