微信图片反防盗链 用js不太成熟的解决方式 仅供参考
$("#imgDiv img").each(function () {
var img = $(this);
var img_src = img.attr("src") + "?" + Math.random();
var frameid = "frameimg" + Math.random();
var image = new Image();
image.src = img_src;
image.onload = function () {
window.img = '<img id="img" src=\'' + img_src + '\'/>';
window.img += '<style></style>';
window.img += '<script>window.onload=function(){';
window.img += 'parent.document.getElementById(\'' + frameid + '\').height=document.getElementById(\'img\').height+\'px\'';
window.img += 'parent.document.getElementById(\'' + frameid + '\').width=document.getElementById(\'img\').width+\'px\'';
window.img += '}<' + '/script>';
img.parent().append('<iframe width="' + image.width + 'px" height="' + image.height + 'px" id="' + frameid + '" src="javascript:parent.img" frameBorder="0" scrolling="no"></iframe>');
img.remove();
}
});
此方法每张图片会创建一个iframe,比较耗费资源,请根据实际情况确定是否使用
ps:此外还要在页面或者模板页中加上:
<meta name="referrer" content="never">
后来需要iframe中的图片最大宽度为800并居中:
$("#imgDiv img").each(function () {
var img = $(this);
var img_src = img.attr("src") + "?" + Math.random();
var frameid = "frameimg" + Math.random();
var image = new Image();
image.src = img_src;
image.onload = function () {
var ff = 1;
if (image.width > 800) {
ff = 800 / image.width;
image.width = 800;
}
window.img = '<img style="max-width:800px" id="img" src=\'' + img_src + '\'/>';
window.img += '<style></style>';
window.img += '<script>window.onload=function(){';
window.img += 'parent.document.getElementById(\'' + frameid + '\').height=document.getElementById(\'img\').height+\'px\'';
window.img += 'parent.document.getElementById(\'' + frameid + '\').width=document.getElementById(\'img\').width+\'px\'';
window.img += '}<' + '/script>';
img.parent().append('<iframe style="display:block;margin:0px auto;overflow:hidden;width:' + image.width + 'px;" height="' + image.height * ff + 'px" id="' + frameid + '" src="javascript:parent.img" frameBorder="0" scrolling="no"></iframe>');
img.remove();
}
});
微信图片反防盗链 用js不太成熟的解决方式 仅供参考的更多相关文章
- HTTP防盗链与反防盗链
HTTP防盗链 通过上一次,我没对HTTP请求不再那么陌生了.防盗链无非就是别人来请求自己网站的信息,用于其他网站,那么如果我们能识别请求是来自那个网站,如果是外网,那么就重定向等其他处理.但在web ...
- 判断终端类型、微信的文章防盗链、h5页面跳转打开新的app、跳转到app市场
判断终端的类型.安卓.ios.微信.qq function GetMobelType() { var browser = { ...
- 微信小程序--基于ColorUI构建皮皮虾短视频去水印组件(仅供学习使用)
微信小程序--基于ColorUI构建皮皮虾短视频去水印组件(仅供学习使用) 没错,我是皮友,我想学习舞蹈(/doge)和瑜伽 ,要无水印的那种有助于我加深学习. 1.组件效果展示 2.组件引入准备 h ...
- 跳过图片反盗链js
页面增加<iframe> <iframe id="ifa" style="display:none" /> 原来html: <im ...
- 【反防盗链】img 标签 访问图片 返回403 forbidden问题
解决方案,页面头添加 <meta name="referrer" content="no-referrer" /> 隐藏请求体中标注来源referr ...
- Nginx图片的防盗链配置
[root@web01 www]# cat /app/server/nginx/conf/vhosts/default.conf server { listen default_server; ser ...
- 破解iframe微信推文(图片)防盗链
$.ajaxPrefilter(function(options) { if(options.crossDomain && jQuery.support.cors) { var htt ...
- Asp.net 图片文件防盗链介绍
想要实现文件放盗链的功能 首先添加一个全局文件 Global.asax 在 Application_BeginRequest中我们可以判断Http报文头中的UrlReferre是否来源本站. if ( ...
- 微信JSSDK javascript 开发 代码片段,仅供参考
最全面最专业的微信公众平台开发教程:http://www.cnblogs.com/txw1958/p/weixin-js-sdk-demo.html 比较完整的分享教程:http://www.cnbl ...
随机推荐
- spring boot 使用spring.resources.static-locations 分离系统模版&&资源文件
方便我们将资源配置以及模版&&静态文件分离出来,而不是打包在一起,比如以下的一个demo 参考配置: server.port=8006 spring.application.name= ...
- lapis docker 运行说明
1. lapis docker 镜像制作 因为openresty 新版本一个json 库的问题,我们使用的是 openresty:1.11.2.1 基础镜像 FROM openresty/openre ...
- gradle 项目构建以及发布maven 私服&& docker 私服构建发布
1. 项目结构 2. 代码说明 a. Dockerfile docker 构建的 FROM openjdk:8-jre-alpine WORKDIR /appdemo/ COPY build/di ...
- 【转】理解 pkg-config 工具
原文网址:http://www.chenjunlu.com/2011/03/understanding-pkg-config-tool/ 你在 Unix 或 Linux 下开发过软件吗?写完一个程序, ...
- python+anaconda+pycharm工具包安装
更新额外包 $ conda update conda 更新pip python -m pip install --upgrade pip 更新所有 conda update --all 安装ffmpe ...
- bzoj 2178 圆的面积并——辛普森积分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2178 把包含的圆去掉.横坐标不相交的一段一段圆分开算.算辛普森的时候预处理 f( ) ,比如 ...
- 优化RequireJS项目(合并与压缩)
关于RequireJS已经有很多文章介绍过了.这个工具可以将你的JavaScript代码轻易的分割成苦 干个模块(module)并且保持你的代码模块化与易维护性.这样,你将获得一些具有互相依赖关系的J ...
- linux mount / umount 命令的基本用法 及 开机自动挂载
格式:mount [-参数] [设备名称] [挂载点] 其中常用的参数有: -a 安装在/etc/fstab文件中类出的所有文件系统. -f 伪装mount,作出检查设备和目录的样子,但并不真正挂载文 ...
- Ubantu 安装fftw3
FFTW官网 FFTW ( the Faster Fourier Transform in the West) 是一个快速计算离散傅里叶变换的标准C语言程序集. ubuntu下安装指令: sudo a ...
- appium+python自动化29-toast
注意 toast要appium1.6.3以上版本才支持,appium1.4的版本就别浪费时间了 Supported Platforms 1.查看appium v1.7版本官方文档 Supported ...