为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用Scriptish向火狐添加innerText属性?

如何使用Scriptish向火狐添加innerText属性?

人到中年有点甜 2019-04-09 20:24:47
首先,是学校的教务网页使用了innerText属性,所以我想自己写一个UserScript脚本来实现innerText属性。其实,只要执行如下脚本后,就有了innerText属性了:if(!!document.getBoxObjectFor||window.mozInnerScreenX!=null){HTMLElement.prototype.__defineGetter__("innerText",function(){returnthis.textContent;});HTMLElement.prototype.__defineSetter__("innerText",function(value){this.textContent=value;});}但是,我自己写了脚本之后,仍然无法设置innerText属性,提示TypeError:HTMLElement.prototype.__defineGetter__isnotafunction请问如何解决?另外,innerText属性在onload代码中就使用了。我觉得Scriptish的权限控制也是需要考虑的。附上我写的测试脚本://==UserScript==//@nameTest//@namespacewww.example.com//@include*//@version1//==/UserScript==if(!!document.getBoxObjectFor||window.mozInnerScreenX!=null){HTMLElement.prototype.__defineGetter__("innerText",function(){returnthis.textContent;});HTMLElement.prototype.__defineSetter__("innerText",function(value){this.textContent=value;});}
查看完整描述

2 回答

?
潇湘沐

TA贡献1816条经验 获得超6个赞

不是权限的原因,而是它本身就没有那个__defineSetter__属性。
Object.defineProperty(HTMLElement.prototype,'innerText',{
get:function(){
returnthis.textContent;
},
set:function(val){
this.textContent=val;
}
})
Firebug控制台测试可行。文档
                            
查看完整回答
反对 回复 2019-04-09
  • 2 回答
  • 0 关注
  • 397 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号