我在WordPress网站上使用水印.js进行图像保护。
在测试时,我在img.src=gcanvas.toDataURL()中发现了一个错误。我试图找到在哪里设置这个值,但到目前为止我一直失败。
这就是我正在使用的代码——有人能看到哪里出了问题吗?
代码
var load = false;
window.onload = function(){
if(!load) {
wmark.init({
/* config goes here */
"position": "top-center", // default "bottom-right"
"opacity": 50, // default 50
"className": "watermark", // default "watermark"
"path": "<?php echo WP_PLUGIN_URL.'/'. dirname(plugin_basename( __FILE__ ));?>/images/watermark.png", // plugindir
});
load = true;
}
}
最后,我研究了自己,并将其作为工作解决方案实现。最后,在这里,最好不要使用dom,只需删除dom并尝试它就可以实现
<script type="text/javascript">
jQuery('img').each(function($) {
jQuery(this).attr('class','watermark');
});
wmark.init({
/* config goes here */
"position": "top-center", // default "bottom-right"
"opacity": 50, // default 50
"className": "watermark", // default "watermark"
"path": "watermark.png", // plugindir
});
</script>