在手机上模拟 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. JDBC的操作总结

    JDBC  操作总结 JDBC是一组能够执行SQL语句的API JDBC的操作方式比较单一,简单的分为以下几个流程:  1.通过数据库厂商提供的JDB类库想DriverManager注册数据库驱动   ...

  2. 把包发布到npm官网

    一.包 包就是多模块的集合,CommonJS的包规范给程序员提供了组织模块的标准,减少沟通成本. 规范: 所有的模块放在demo文件夹下(包名)的lib文件夹里面 在lib文件夹的同级目录下新建ind ...

  3. IOS进阶之WKWebView

    前言 Xcode8发布以后,编译器开始不支持IOS7,所以很多应用在适配IOS10之后都不在适配IOS7了,其中包括了很多大公司,网易新闻,滴滴出行等.因此,我们公司的应用也打算淘汰IOS7. 支持到 ...

  4. 怎么理解js中的事件委托

    怎么理解js中的事件委托 时间 2015-01-15 00:59:59  SegmentFault 原文  http://segmentfault.com/blog/sunchengli/119000 ...

  5. linux 下查看cpu位数 内核等参数命令(转)

    # uname -a Linux euis1 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux ( ...

  6. wpf的UserControl用户控件怎么添加到Window窗体中

    转载自 http://www.cnblogs.com/shuang121/archive/2013/01/09/2853591.html 我们来新建一个用户控件UserControl1.xaml &l ...

  7. 跨域AJAX的实现

    跨域 当试图从一个域向另一个域发起请求时   jsonp html中所有带src属性的标签都可以跨域,如:script,img,iframe 可以通过script加载其它域的一段动态脚本,这段脚本包含 ...

  8. Mahout之数据承载

    转载自:https://www.douban.com/note/204399134/ 推荐数据的处理是大规模的,在集群环境下一次要处理的数据可能是数GB,所以Mahout针对推荐数据进行了优化. Pr ...

  9. Guava学习笔记(一)概览

    Guava是谷歌开源的一套Java开发类库,以简洁的编程风格著称,提供了很多实用的工具类, 在之前的工作中应用过Collections API和Guava提供的Cache,不过对Guava没有一个系统 ...

  10. Python学习笔记(3)

      1.元组 元组的定义符号是() ,元素定义与列表完全一致.不同的是元组的内容是不可变的. 2.字典 字典里面的内容是无序的. 字典的元素组成形式是 key:value key的定义规则:key是不 ...