在手机网页上模拟 js 控制台
在手机上模拟 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 控制台的更多相关文章
- 网页上的JS call Unity3d里的function——SendMessage
注意: sendmessage只可以从网页发信息到unity游戏里,但是没有返回值 只可以发布三种类型的data,不可以其他复杂的强类型 发信息的时不会做编译检测 SendMessage Workfl ...
- 通过钉钉网页上的js学习xss打cookie
做完了一个项目,然后没啥事做,无意看到了一个钉钉的外部链接: 题外话1: 查看源码,复制其中的代码: try { var search = location.search; if (search &a ...
- HTML5的audio在手机网页上无法自动加载/播放音乐,能否实现该功能?
在IOS中第一次调用play方法播放音频会被阻止,必须得等用户有交互动作,比如touchstart,click后才能正常调用,在微信中可以通过监听WeixinJSBridgeReady事件来提前播放一 ...
- html5 DeviceOrientation来实现手机网站上的摇一摇功能
原文地址:http://www.cootm.com/?p=706 从网上转载看到的,感觉不错,就转过来了,特此感谢 cnblogs 的 幸福2胖纸的码农生活,直接转载了,不要介意!呵呵 以下是转载内容 ...
- 利用HTML5的一个重要特性 —— DeviceOrientation来实现手机网站上的摇一摇功能
介绍之前做两个声明: 以下代码可以直接运行,当然你别忘了引用jQuery才行. <script> // DeviceOrientation将底层的方向传感器和运动传感器进行了高级封装, ...
- chorme插件 ,在浏览器上模拟手机,pad 查看网页|前端技术开发必备插件
网址:http://lab.maltewassermann.com/viewport-resizer/使用方法:1在chrome浏览器上方右击,显示书签栏 2 打开插件网址,将<ignore_j ...
- JS让网页上文字出现键盘打字的打字效果
一个挺简单的网页特效:JS让网页上文字出现键盘打字的打字效果实现 演示地址:http://codepen.io/guihailiuli/pen/jPOYMZ 以代码形式实现过程分析: <html ...
- JS文件中的中文在网页上显示为乱码解决方法
转自:http://www.pc6.com/infoview/Article_63835.html 如果JS文件中的中文在网页上显示为乱码,不妨采用本文章中的方法来试一试,或许能解决使你很头疼的问题. ...
- HTML5手机应用的最大优势就是可以在网页上直接调试和修改
HTML5手机应用的最大优势就是可以在网页上直接调试和修改
随机推荐
- jsonp是什么【转载自JavaScript微信公众号】
转自 http://mp.weixin.qq.com/s/xNnKAeLv6sO0T-IvP2AUlQ JavaScript微信公众号 一.JSONP的诞生 首先,因为ajax无法跨 ...
- 何为HDFS?
该文来自百度百科,自我收藏. Hadoop分布式文件系统(HDFS)被设计成适合运行在通用硬件(commodity hardware)上的分布式文件系统.它和现有的分布式文件系统有很多共同点.但同时, ...
- Mac下没有权限启动tomcat的解决办法
问题描述 在Mac中通过./startup.sh执行启动脚本文件,启动tomcat时报如下错误: -bash: ./startup.sh: Permission denied 解决方法 错误信息说明了 ...
- web适配问题
bootstrap模板为使IE6.7.8版本(IE9以下版本)浏览器兼容html5新增的标签,引入下面代码文件即可. <script src="https://oss.maxcdn.c ...
- axure的一些注意事项
1. 不要轻易用中继器的 载入时 事件, 感觉存在bug 2. 元件在显示和隐藏的动画过程中,不要去取他的x,y值,有几率会取成0,也不要去获取它的尺寸,只有在动画完成后才能获得 3. 装着一个中继器 ...
- 小tips
ios::sync_with_stdio(false); 加速读入的,加上这条语句可以使cin和cout的速度和scanf和printf差不多.
- DP套DP HDOJ 4899 Hero meet devil(国王的子民的DNA)
题目链接 题意: 给n长度的S串,对于0<=i<=|S|,有多少个长度为m的T串,使得LCS(S,T) = i. 思路: 理解的不是很透彻,先占个坑. #include <bits/ ...
- R内存管理与垃圾清理
1.内存查看 memory.limit():查看内存大小 memory.limit(n):申请内存大小 memory.size(NA):查看内存大小 memory.size(T):查看已分配的内存 m ...
- Web前端性能测试-性能测试知多少---深入分析前端站点的性能
针对目前接手的web前端的性能,一时间不知道从什么地方入手,然后经过查找资料,发现其实还是蛮简单的. 前端性能测试对象: HTML.CSS.JS.AJAX等前端技术开发的Web页面 影响用户浏览网页速 ...
- Thinkphp的初级注意点
开头话: 网站,说实话,是第一次做,也就直接选择了ThinkPHP这个开源框架.选择这个框架的原因...已经不记得了 貌似在我当时的认知中只有这个了,其它更优秀的框架也是这个毕业设计做到后期再去了解的 ...