在手机上模拟 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. CSS 布局

    近日开发中,总感觉页面布局方面力不从心.以前也曾学过这方面的内容,但是不够系统,因此我打算整理一下. 在web 页面中一般有 table 和 css+div 两种布局方式. 其中css+div 又分为 ...

  2. MongoDB的分片(9)

    什么是分片 分片是指将数据库拆分,将其分散在不同的机器上的过程.将数据分散到不同的机器上,不需要功能强大的服务器就可以存储更多的数据和处理更大的负载.基本思想就是将集合切成小块,这些块分散到若干片里, ...

  3. Codeigniter的Redis使用

    1. ./config/redis.php: <?php $config['redis_host'] = '127.0.0.1'; $config['redis_port'] = '6379'; ...

  4. yum 源

    epel 6源: cd /usr/local/src wget https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noar ...

  5. 基于Netty与RabbitMQ的消息服务

    Netty作为一个高性能的异步网络开发框架,可以作为各种服务的开发框架. 前段时间的一个项目涉及到硬件设备实时数据的采集,采用Netty作为采集服务的实现框架,同时使用RabbitMQ作为采集服务和各 ...

  6. 移动端webapp自适应实践(css雪碧图制作小工具实践)图文并茂

    为什么要写这个 以前写过关于webapp自适应屏幕的文章(链接),不过写的大多数群众看不懂,所以来个图文并茂的版本.虽然只是一个简单的页面,不过在做的过程中也遇到了一些问题,也算是好事吧! 该示例gi ...

  7. jq 剪切板

    文章链接 http://www.cnblogs.com/lkxsnow/p/5372665.html http://www.w3cfuns.com/notes/17735/020c2e68a60342 ...

  8. MD5验证

    commons-codec包可以从apache下载:http://commons.apache.org/codec/download_codec.cgi MD5现在是用来作为一种数字签名算法,即A向B ...

  9. LeetCode 1. Two Sum

    Problem: Given an array of integers, return indices of the two numbers such that they add up to a sp ...

  10. BaaS、IaaS、PaaS、SaaS

    参考资料:http://www.zhihu.com/question/23048744