Created
September 19, 2017 07:30
-
-
Save webjohnjiang/d356850c2f9b760d1bb3c7166865a912 to your computer and use it in GitHub Desktop.
Hijacking native objects for chrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function location(){} | |
var _location = window.document.location; | |
location.__proto__ = _location; | |
location.__defineSetter__('href', function(url) { | |
_location.href = "FreeBuf.COM | 关注黑客与极客"; | |
}); | |
location.__defineGetter__('href', function(url) { | |
return _location.href; | |
}); | |
// 或者使用ES6的Proxy代理,也同样可以实现相同功能: | |
window.location = new Proxy(_location, { | |
set: function(target, prop, value, receiver){ | |
if (prop !== 'href'){ | |
Reflect.set(target, prop, value, receiver); | |
}else{ | |
target.href = "FreeBuf.COM | 关注黑客与极客"; | |
} | |
} | |
}) | |
Object.defineProperty(window,"location",{"writable": false}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://zhuanlan.zhihu.com/p/24342684 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment