在手机上模拟 console  做一些简单代码调试

在工作机上编辑好代码用QQ 之类的工具传到 手机上在调试
当然你也可以尝试用一只手指写代码的壮举
设置 window.console = mobiDebug 可以在手机上显示控制台信息

/****
mobiDebuggerHelper.js
by cnblogs.com/ecalf
*****/
var mobiDebug = {
init:function(lauch){
var holder = document.createElement('div');
var toolbar = document.createElement('div');
var content = document.createElement('div');
var editor = document.createElement('div');
var board = document.createElement('div'); var textarea = document.createElement('textarea'); holder.appendChild(toolbar);
holder.appendChild(content);
content.appendChild(editor);
content.appendChild(board);
editor.appendChild(textarea); holder.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;z-index:9999;background:black;padding:30px 5px;display:none;font-size:14px;font-family:"Courier New";text-align:left;';
toolbar.style.cssText = 'position:absolute;top:0;height:30px;text-align:right;line-height:30px;';
toolbar.innerHTML = '<button id="btnDebugClose">关闭</button><button id="btnDebugReload">刷新</button><button id="btnDebugClear">清除</button><button id="btnDebugInput">编辑</button><button id="btnDebugSubmit">执行</button>';
content.style.cssText = 'position:absolute;line-height:150%;top:30px;left:0;bottom:5px;right:0;background:white;color:black;';
board.style.cssText = 'position:relative;width:100%;height:100%;overflow-y:auto;overflow-x:hidden;display:none;';
textarea.style.cssText = 'position:absolute;top:0;left:0;bottom:0;right:0;width:100%;height:100%;'; document.body.appendChild(holder);
this.holder = holder;
this.editor = editor;
this.board = board; var host = this;
var count = 0,timer=0; //启动调试
if(!lauch){
lauch = document.body;
}else if(typeof(lauch)=='string'){
lauch = document.getElementById(lauch);
} lauch.onclick = function(){
if(host.holder.style.display!='none'){ return;} if(!timer){
timer = setTimeout(function(){
count = 0;
},5000);
} count+=1; if(count==4){
host.show();
count = 0;
clearTimeout(timer);
}
}; document.querySelector('#btnDebugClose').onclick = function(){
host.show(false);
};
document.querySelector('#btnDebugReload').onclick = function(){
location.reload();
};
document.querySelector('#btnDebugInput').onclick = function(){
host.showEditor();
};
document.querySelector('#btnDebugSubmit').onclick = function(){
host.test();
};
document.querySelector('#btnDebugClear').onclick = function(){
if(host.editor.style.display!='none'){
textarea.value='';
}else{
host.board.innerHTML='';
}
}; return this;
},
show:function(frag){
this.holder.style.display=frag===false?'none':'block'; return this;
},
showEditor:function(frag){
this.editor.style.display=frag===false?'none':'block';
this.board.style.display=frag===false?'block':'none';
return this;
},
showLog:function(frag){
this.board.style.display=frag===false?'none':'block';
this.editor.style.display = frag===false?'block':'none';
return this;
},
log:function(){// var mobiConsole = this; mobiConsole.log('hello world','color:red'); the scope this is mobiConsole,not window
var p = document.createElement('p');
var args = arguments;
var color = args[args.length-1];
if((/^colou?r:/i).test(color)){
p.style.color = color.split(':')[1];
args = [].slice.apply(args,[0,-1]);
}else{
args = [].slice.apply(args,[0]);
} var s = args.join(' ').replace(/[<>]/g,function(s){ return '&#'+s.charCodeAt(0);}); p.innerHTML = s;
this.board.appendChild(p);
return this;
},
getCode:function(){
var code = this.editor.querySelector('textarea').value;
return new Function(code);
},
test:function(){
var fun = this.getCode();
fun.call(this);
this.showEditor(false).showLog();
return this;
} }; use like this...
mobiDebug.init($(".header .menu").get(0));

在手机网页上模拟 js 控制台的更多相关文章

  1. 网页上的JS call Unity3d里的function——SendMessage

    注意: sendmessage只可以从网页发信息到unity游戏里,但是没有返回值 只可以发布三种类型的data,不可以其他复杂的强类型 发信息的时不会做编译检测 SendMessage Workfl ...

  2. 通过钉钉网页上的js学习xss打cookie

    做完了一个项目,然后没啥事做,无意看到了一个钉钉的外部链接: 题外话1: 查看源码,复制其中的代码: try { var search = location.search; if (search &a ...

  3. HTML5的audio在手机网页上无法自动加载/播放音乐,能否实现该功能?

    在IOS中第一次调用play方法播放音频会被阻止,必须得等用户有交互动作,比如touchstart,click后才能正常调用,在微信中可以通过监听WeixinJSBridgeReady事件来提前播放一 ...

  4. html5 DeviceOrientation来实现手机网站上的摇一摇功能

    原文地址:http://www.cootm.com/?p=706 从网上转载看到的,感觉不错,就转过来了,特此感谢 cnblogs 的 幸福2胖纸的码农生活,直接转载了,不要介意!呵呵 以下是转载内容 ...

  5. 利用HTML5的一个重要特性 —— DeviceOrientation来实现手机网站上的摇一摇功能

      介绍之前做两个声明: 以下代码可以直接运行,当然你别忘了引用jQuery才行. <script> // DeviceOrientation将底层的方向传感器和运动传感器进行了高级封装, ...

  6. chorme插件 ,在浏览器上模拟手机,pad 查看网页|前端技术开发必备插件

    网址:http://lab.maltewassermann.com/viewport-resizer/使用方法:1在chrome浏览器上方右击,显示书签栏 2 打开插件网址,将<ignore_j ...

  7. JS让网页上文字出现键盘打字的打字效果

    一个挺简单的网页特效:JS让网页上文字出现键盘打字的打字效果实现 演示地址:http://codepen.io/guihailiuli/pen/jPOYMZ 以代码形式实现过程分析: <html ...

  8. JS文件中的中文在网页上显示为乱码解决方法

    转自:http://www.pc6.com/infoview/Article_63835.html 如果JS文件中的中文在网页上显示为乱码,不妨采用本文章中的方法来试一试,或许能解决使你很头疼的问题. ...

  9. HTML5手机应用的最大优势就是可以在网页上直接调试和修改

    HTML5手机应用的最大优势就是可以在网页上直接调试和修改

随机推荐

  1. iOS 之图片尺寸

    打包上线需要的图标 启动图片 本地需要的图标 参考 参考1:http://blog.csdn.net/kepoon/article/details/39693591 参考2:https://devel ...

  2. zend studio 13.5破解以及集成xdebug

    环境说明: 操作系统:Windows 7 Ultimate Edition Service Pack 1 PHP:7.0.11 TS Zend Studio:13.5.0 Xdebug:2.5.0 一 ...

  3. 素数的平方阶群必为Abel群

    定理  设$p$为素数,则$p^2$阶群$G$必为Abel群.

  4. 解决CURL 请求本地超时

    首先,这样的问题只会出现在Windows+Nginx中. php-cgi 默认使用的是9000端口,即使多个进程也并发的是9000端口 在用户访问一个php页面的时候nginx已将该进程占用,在该进程 ...

  5. Quart.NET实施参考

    参考 1.博客园: http://www.cnblogs.com/lzrabbit/archive/2012/04/13/2447609.html 2.官网:http://www.cnblogs.co ...

  6. HBase基本shell命令

    HBase基本shell命令 以下shell命令都是经过测试,正常展示,若有不足,还望指点! 1.创建表 create ‘表名称’,‘列族名称1’,‘列族名称1’create 'test_M_01', ...

  7. WebAPI图片上传

    public Task<HttpResponseMessage> PostFormData() { // Check if the request contains multipart/f ...

  8. VS2013如何避开安装时IE10的限制

    [VS2013]如何避开VS2013必须要有IE10的限制 VS就会告诉我们目前环境不适合安装VS2013,必须升级IE版本到IE10. 在不安装IE10时的时候,安装办法: 将下面一段文字,储存为. ...

  9. tecplot 脚本文件

    一个简单的C++代码,可以生成tecplot的脚本文件,打开文件就能自动绘图.绘图过程是先把文件导入,然后镜像,最后生成一个动画,但是导入的文件名称要求是有规律的. /* ** This progra ...

  10. Qt实现端口扫描器

    首先展示一下效果: 界面通过Qt设计师做出来的. 主要有两个类. 首先主函数: #include "mainwindow.h" #include <QApplication& ...