博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
邪恶的AJAX:使用jQuery的Spyjax
阅读量:2518 次
发布时间:2019-05-11

本文共 3121 字,大约阅读时间需要 10 分钟。

Last year I wrote a popular post titled AJAX For Evil: Spyjax when I described a technique called "Spyjax":

去年,当我描述一种称为“ Spyjax”的技术时,我写了一篇热门文章《 AJAX For Evil:Spyjax》:

Spyjax, as I know it, is taking information from the user's computer for your own use — specifically their browsing habits. By using CSS and JavaScript, I can inject anchor links into the page and tell whether you've been to the link's URL. How? Quite easy actually.
据我所知,Spyjax正在从用户计算机中获取信息供您自己使用-特别是他们的浏览习惯。 通过使用CSS和JavaScript,我可以在页面中注入锚链接,并告诉您是否访问过链接的URL。 怎么样? 实际上很容易。

I've taken the time to demonstrate this technique using jQuery.

我花了一些时间来使用jQuery演示这种技术。

CSS (The CSS)

a.checkme			{ color:#00ff00; }a.checkme:visited	{ color:#ff0000; }

The most important part of the CSS is the difference in ":link" and ":visited" color; the method by which we can tell if a site has been visited is by its link color being the ":visited" color.

CSS最重要的部分是“:link”和“:visited”颜色的区别; 我们可以通过链接颜色为“:visited”(访问)颜色来判断网站是否已被访问的方法。

jQuery JavaScript (The jQuery JavaScript)

//when the page is ready$(document).ready(function() {	//the list of domains to check and an array which will store hits	var domains = ['davidwalsh.name','css-tricks.com','scriptandstyle.com','cnn.com','digg.com'];	var visited = [];	//for every domain...	$.each(domains,function() {		//inject a link into page		var a = $('').attr({			href: 'http://' + this,			'class': 'checkme'		}).appendTo(document.body);		//check the color of the link		if($(a).css('color') == '#ff0000' || $(a).css('color') == 'rgb(255, 0, 0)') { //either format of color			$(a).addClass('highlight');			visited.push(this);		}		//remove from the page -- no longer need the links		a.remove();	});	if(visited.length) {		//save via ajax!  shady!		//display items on the page based on "hits"	}});

We start by injecting a bunch of hidden links into the page (unbeknownst to the user). For each link we've injected into the page, our jQuery JavaScript grabs the link color -- if the link's color matches the designated ":visited" link color we set via CSS, we've found a site the user's been to. Of course we can do anything we want with that information, including saving it via AJAX. Why? Well, if we know a user has been to Digg.com, maybe we show the Digg "share" icon instead of the Reddit icon.

首先,将一堆隐藏的链接注入到页面中(用户不知道)。 对于我们注入到页面中的每个链接,我们的jQuery JavaScript都会获取链接颜色-如果该链接的颜色与我们通过CSS设置的指定“:visited”链接颜色相匹配,那么我们已经找到了用户访问过的网站。 当然,我们可以使用该信息做任何想要的事情,包括通过AJAX保存它。 为什么? 好吧,如果我们知道某个用户访问过Digg.com,也许我们会显示Digg“共享”图标而不是Reddit图标。

MooTools JavaScript (The MooTools JavaScript)

var domains = ['davidwalsh.name','css-tricks.com','scriptandstyle.com','cnn.com','digg.com'];var visited = [];domains.each(function(url) {	var anchor = new Element('a', {		href: 'http://' + url,		'class': 'checkme',		html: url	}).inject(document.body);	if(anchor.getStyle('color') == '#ff0000') {		visited.push(url);	}	anchor.dispose();});

The above code accomplishes the same task using MooTools as outlined in my .

上面的代码使用MooTools完成了我概述的相同任务。

What are your thoughts on Spyjax? Harmless? Major privacy violation? You tell me!

您对Spyjax有什么想法? 无害? 严重侵犯隐私? 你告诉我!

翻译自:

转载地址:http://yuvwd.baihongyu.com/

你可能感兴趣的文章
Java--面试通关要点
查看>>
iOS 消息推送原理
查看>>
随笔1
查看>>
Codeforces 731 C.Socks-并查集+STL(vector+map)
查看>>
洛谷 P3383 【模板】线性筛素数-线性筛素数(欧拉筛素数)O(n)基础题贴个板子备忘...
查看>>
C语言中的正负数及其输出以及小数
查看>>
Android Fragments 详细使用
查看>>
【转】MySQL-Utilities,mysql工具包
查看>>
使用echarts实现了一个折现图,数据是一天24小时
查看>>
杂项:game_navigation
查看>>
建站手册-职业规划:职业资源
查看>>
基于 Generator 和 Iterator 的惰性列表
查看>>
身为前端开发工程师,你需要了解的搜索引擎优化SEO.
查看>>
一篇文章掌握nightwatch自动化测试
查看>>
vue 上传图片到阿里云(前端直传:不推荐)
查看>>
求最大区间,使得特定的两个数的个数相等
查看>>
node读写Excel操作
查看>>
双飞翼布局
查看>>
android利用wireshark抓包
查看>>
Mac和Windows系统下Mysql数据库的导入导出
查看>>