admin管理员组文章数量:1293530
How would I go about removing a function if a certain browser is detected ? Here is the function and the detection:
function parallaxIt(e, target, movement) {
var $this = $("#app");
var relX = e.pageX - $this.offset().left;
var relY = e.pageY - $this.offset().top;
TweenMax.to(target, 1, {
x: (relX - $this.width() / 2) / $this.width() * movement,
y: (relY - $this.height() / 2) / $this.height() * movement,
z: 0.01,
rotation:0.01
});
}
var version = detectIE();
if (version === false) {
//Do Nothing
} else if (version >= 12) {
//Remove Function
} else {
$("#iefix").attr({href : "/static/css/app-iefix.css"});
//Remove Function
}
So when any IE is detected I want to remove the function parallaxIt()
or break it so It doesn't work any ideas?
Kind Regards
(the detect part of the code is obviously a small snippet of the full code so it's easier for you folks to read instead of going through the full code)
How would I go about removing a function if a certain browser is detected ? Here is the function and the detection:
function parallaxIt(e, target, movement) {
var $this = $("#app");
var relX = e.pageX - $this.offset().left;
var relY = e.pageY - $this.offset().top;
TweenMax.to(target, 1, {
x: (relX - $this.width() / 2) / $this.width() * movement,
y: (relY - $this.height() / 2) / $this.height() * movement,
z: 0.01,
rotation:0.01
});
}
var version = detectIE();
if (version === false) {
//Do Nothing
} else if (version >= 12) {
//Remove Function
} else {
$("#iefix").attr({href : "/static/css/app-iefix.css"});
//Remove Function
}
So when any IE is detected I want to remove the function parallaxIt()
or break it so It doesn't work any ideas?
Kind Regards
(the detect part of the code is obviously a small snippet of the full code so it's easier for you folks to read instead of going through the full code)
Share Improve this question edited Jan 2, 2019 at 15:56 IndexOutOfDevelopersException 1,3547 gold badges15 silver badges28 bronze badges asked Jan 2, 2019 at 12:49 user3112634user3112634 6934 gold badges10 silver badges30 bronze badges 6- 1 Just don't call it in the first place if IE is being used. – Quentin Commented Jan 2, 2019 at 12:50
- It triggers on window.onload – user3112634 Commented Jan 2, 2019 at 12:51
- 2 So change the window.onload function so it tests if the browser is IE first! – Quentin Commented Jan 2, 2019 at 12:52
- I know I can add parallaxIt() in else if and else of the detection but I would still want to know how to remove a function all together – user3112634 Commented Jan 2, 2019 at 12:56
- 1 Delete all references to it. How you do that depends on where the references are. It's entirely possible that you end up generating Reference Errors because the function no longer exists but other code still tries to call it. This is one reason the "delete the function" approach is a bad one. It's massively over plicated. – Quentin Commented Jan 2, 2019 at 12:56
1 Answer
Reset to default 6At least for me in Chrome v71 (Windows 10), deleting the function does not do anything (it keeps existing). But you can re-assign it to bee a no-op function:
function parallaxIT() {
console.log("inside parallaxIT");
}
// delete
delete window.parallaxIT;
console.log("parallaxIT was 'deleted', does it still show output:");
parallaxIT();
console.log("=====");
// re-assign
window.parallaxIT = function() {} // no-op function
console.log("parallaxIT was re-assigned, does it still show output:");
parallaxIT();
console.log("=====");
本文标签: jqueryHow to removedelete a JavaScript function()Stack Overflow
版权声明:本文标题:jquery - How to removedelete a JavaScript function()? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741579061a2386464.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论