别名为chrome console.log [英] alias to chrome console.log

查看:236
本文介绍了别名为chrome console.log的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  // //创建一个xss控制台日志

var cl =(typeof(console)!='undefined')? console.log:alert;
cl('teste');

输出:Uncaught TypeError:非法调用

谢谢。

解决方案当您编写 cl(); 在全球范围内调用 log



Chrome的 console.log 不希望在窗口对象上调用。



相反,您可以写

  cl = function(){return console.log.apply(console,arguments); }; 

这将在上下文中调用 log 控制台


I would like to know why the follow code doesn't work in the Google Chrome:

// creates a xss console log

var cl = ( typeof( console ) != 'undefined' ) ? console.log : alert;
cl('teste');

output: Uncaught TypeError: Illegal invocation

thanks.

解决方案

When you write cl();, you're calling log in the global context.

Chrome's console.log doesn't want to be called on the window object.

Instead, you can write

cl = function() { return console.log.apply(console, arguments); };

This will call log in the context of console.

这篇关于别名为chrome console.log的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆