使用纯JavaScript返回并嵌入图像,如php



我无法确定是否可以将 html 或 js 文档嵌入为图像,如下所示:

<img src="http://blah.com/image.js" />

<img src="http://blah.com/image.html" />

一般的想法是,当浏览器尝试访问文件时,它将执行文件客户端并获取实际图像,然后像往常一样嵌入它。我意识到这可以通过PHP轻松完成,但我正在寻找非服务器解决方案。

问题是它传输的内容类型是错误的,更重要的是,我认为这违反了每个跨域和沙盒规则,我认为没有任何办法。

只要您链接到的文档可以显示二进制数据,就可以了。

按照这篇文章来解决使用javascript的二进制负载,http://emilsblog.lerch.org/2009/07/javascript-hacks-using-xhr-to-load.html

然后,您还可以在img标签中包含base64数据,如下所示

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAIAAABL1vtsAAAYImlDQ1BJQ0MgUHJvZmlsZQAAWAmtWXk4Vd333+fOLtc8z/M8y5x5zpiZiGue47qENBhSoYEkohQyFg1CUkKoSIZCoTQIUSmkDPlt3nrf9/t8n+9/v/M8d5/PWeez11577XX2XntfALjryJGRYShGAMIjqBR7M0NBVzd3QfwYIAA0AAAFiGTf6EgDOzsr+PQ/ru9DANl8NSi3qet/kP6XmMnPP9oXAMQOEnz8on3DIa4DAN3oG0mhAoDd1Ce6lxq5iU9BzEqBBkJcuokD/8KNm9jnL9yzxXG0N4KcCQAIdGQyJRAA0hyUC8b6BkI99HQA4Jgj/IIjYDVBiHV9g8h+AHB7Q45sePieTZwJsaTPv/QE/guTyT5/6ySTA//Gf/UF1oQNGwdHR4aR47ce/j+L8LAY6K+tix+WdNGhDpbwzg79FudLNnGAmBPiE0H+Fla/5WWRVEP73/LmYKqFI8SskPMsKMbc6Teejgl1MoCYF8rXQvdYbvKhn1CcET42thAzQyzqG20Efb/ZFkotIcjR5TfHys/f2ARiGEUoV8oe+z/8oOhYhz/yhIQgI5s//BDyjs3xpof8dDIFoi17UHn+YWab7QpD+ZVIqt2mnZtt9UaE2fzuC+p9AMV0k7MpX/GP3urvpm1B1CBHcyiHNqMZqR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RuCZ5LiBXtTH0EBjJQ6RK18e/CgsbDQgkQQQ4axrD8U048EJNPRankBENyR5+O7LN2dgvLx03Xspg+FjsqF+bnKQhPiaNVuTTz4VVoQ1t4U6yxucUKBFVpWU4+8k+MymK+cuK5bIqhCOTS0k6fiXX78QBMalZQmM9+ez3KhMIKrgtHtzVvb1/f2hHsSgbVUqCxDU3ApTFE6SYh/GziM1sbItHO3kuF3Pf87JQ9l7Fn0pmZTz+ERTfU1R9vIAw9d6rcLVxn6ilSySQxJVLJaMfBaMcBZhWlQn75T7Ywlyn+mg40tyYTcWCSKVcGZzUqvFskiUoMpRImftUc79loLPyEzW3o9VABMzXIXCjpMx/uqnAcqyVjw3Ad3j2Sy/nRYK80xonB+CB4CeZWzA3TuAMwmcvEqzC9ZxWSvwX2imtXh8xmrRlkxCDpD4YE+XGqJVgrsObjd4DKSCf9stlZ9nl3waphQRpe8N1Uj9WNWxSBLDcekrg6nt0JJnNvcJFc2HFBUA4L10NNZS8zGRZ4OBlsrokNbGYn6CCTAf8AYoEONBF7fygAAAAASUVORK5CYII=" />

src 属性必须指向最终生成实际图像数据的 URI。也许您应该考虑将其留空,然后创建一个脚本来生成data: URI 并将其替换为属性。

相关内容

  • 没有找到相关文章

最新更新