在手机网页上模拟 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手机应用的最大优势就是可以在网页上直接调试和修改
随机推荐
- wps恢复经典模式
经典模式 情况一: 恢复的方法:点击红色区域 情况二: 恢复的方法:点击红色区域
- linux I/O复用
转载自:哈维.dpkirin url:http://blog.csdn.NET/zhang_shuai_2011/article/details/7675797 http://blog.csdn.Ne ...
- MySQL重置root密码
1,以管理员身份进入cmd命令行,输入命令:Net stop mysql; 2 ,进入mysql安装目录的bin文件夹下,执行mysqld --skip-grant-tables 启动MySQL S ...
- 请慎用java的File#renameTo(File)方法
转载地址:http://xiaoych.iteye.com/blog/149328 以前我一直以为File#renameTo(File)方法与OS下面的 move/mv 命令是相同的,可以达到改名.移 ...
- BigDecimal 处理集合
1 创建一个BigDecimal 对象 BigDecimal Sum = new BigDecimal(0); 2 一个BigDecimal 对象,保留2位小数点 Sum.setScale(2,B ...
- Android MarginEnd与MarginStart (RTL)
Android MarginLeft与MarginStart的区别http://blog.csdn.net/zhufuing/article/details/40181815 在写layout布局的时 ...
- 解决升级PHP7后 微信公众号收不到消息
服务器配置Linux+Nginx+PHP5.5+mysql index方法配置微信的关注回复.菜单事件.多客服.自动回复等 public function actionIndex() { if (is ...
- .NET轻量级任务任务管理类
概述 最近做项目总是遇到服务跑批等需求,一直想写个任务管理的DLL,现在整理了一下思路,编写了一个DLL类库,使用方便.只要调用的子类继承服务基类便可以实现任务的整体调度.先看看页面效果: 使用方式 ...
- XmlValidationHelper XSD、Schema(XmlSchemaSet)、XmlReader(XmlValidationSettings)、XmlDocument、XDocument Validate
namespace Test { using Microshaoft; using System; using System.Xml; using System.Xml.Linq; class Pro ...
- CozyRSS开发记录14-RSS源管理初步完工
CozyRSS开发记录14-RSS源管理初步完工 1.添加源的响应 DialogHost.Show有几个版本的重载,加一个DialogClosingEventHandler参数.我们让添加源对话框的添 ...