webview页面和壳通信的库(精简版)
// PG精简版
(function() {
var PG = {
iosBridge: null,
callbackId: 0,
callbacks: [],
commandQueue: [],
commandQueueFlushing: false
},
ua = navigator.userAgent,
isIOS = (ua.indexOf("iPhone") > -1 || ua.indexOf("iPad") > -1 || ua.indexOf("iPod") > -1) ? true : false;
PG.getAndClearQueuedCommands = function () {
var commandQueue_json = JSON.stringify(PG.commandQueue);
PG.commandQueue = [];
return commandQueue_json;
}; PG.exec = function(method, callback, args) {
var callbackId = '';
if (typeof(callback) == "undefined") {
callback = null;
}
if (typeof(args) == "undefined") {
args = {};
} if (callback && typeof(callback) == 'function') {
callbackId = method + PG.callbackId++;
PG.callbacks[callbackId] = callback;
} var obj = {
Method: method,
CallbackId: callbackId,
Args: args
}; if (isIOS) {
if (PG.iosBridge == null) {
PG.iosBridge = document.createElement("iframe");
PG.iosBridge.setAttribute("style", "display:none;");
PG.iosBridge.setAttribute("height", "0px");
PG.iosBridge.setAttribute("width", "0px");
PG.iosBridge.setAttribute("frameborder", "0");
document.documentElement.appendChild(PG.iosBridge);
} PG.commandQueue.push(JSON.stringify(obj));
if (!PG.commandQueueFlushing) {
PG.iosBridge.src = 'pg://ready';
} } else if (window.comjs) {
// android
window.comjs.notify('pg://' + encodeURIComponent(JSON.stringify(obj)));
} else {
console.log("非ios或android平台,不合适吧");
} }; PG.callback = function(callbackId, args) {
if (PG.callbacks[callbackId]) {
try {
var temp = decodeURIComponent(args),
obj = JSON.parse(temp); PG.callbacks[callbackId](obj); } catch (e) {
console.log("Error in success callback: " + callbackId + " = " + e);
} delete PG.callbacks[callbackId]; }
}; if (typeof(window) === "object" && typeof(window.document) === "object") {
window.PG = PG;
} })();
webview页面和壳通信的库(精简版)的更多相关文章
- webview页面间的通信问题
前提 记一次多页面开发. 开发需求时会对页面刷新(reload),返回到上一页(用户返回 / history.go()) 页面间的通信 sessionStorage保存本次会话的信息,同步到新页面或上 ...
- ip 淘宝ip库 精简版
<?php header('Content-type: text/html; charset=utf-8'); //根据ip获取城市.网络运营商等信息 function findCityByIp ...
- Android WebView页面加载优化
目前webapp越来越多,体验也越来越好,为了能够更好的使用WebView展示出流畅的的页面,可以从以下几点做优化: WebView缓存 资源文件本地存储 减少耗时操作 客户端UI优化 可能有人会说了 ...
- webview页面缩放 & 自适应
0.webview页面自适应: // 1.LayoutAlgorithm.NARROW_COLUMNS : 适应内容大小// 2.LayoutAlgorithm.SINGLE_COLUMN:适应屏幕, ...
- iOS开发Safari调试WebView页面
App混合开发现已是常态,不过作为app端开发人员,对H5页面的使用,可不能简单的局限于使用,一些简单的调试方法还是有必要了解的. 关于如何在使用webview过程中,如何对web内对内容进行调试,这 ...
- Chrome Inspect不显示Webview页面的问题总结
首先,确保手机打开了USB调试.如果还是检测不到WebView页面,主要有以下几种情况. 1.反应慢,稍等一会 2.关闭然后重新打开USB调试开关,刺激一下chrome,我的魅族手机有时需要这样操作一 ...
- 微信小程序web-view页面安卓下显示空白的解决办法!!!
web-view页面在你向地址拼接参数展示页面时,在安卓上有时会显示空白 解决方案: A: 普通不需要参数的话可以直接把地址写在src里,不要去在onLoad里获取你的全局变量后再赋值. B: 如果需 ...
- js 页面间的通信
看了一下公司原来的代码,原页面ajax post返回一个页面完整的HTML,然后再打开一个新页面并输出ajax返回的所有代码到新页面上,在新页面上以表单提交的形式实现重定向. 任凭我想了半天也没想出来 ...
- SSE两个页面的相互通信
两个页面之间互相通信 首先搭建express框架,然后通过two页面发送数据给服务器,服务器把数据传送给one页面 在two 中发送数据,在one中显示 router/index.js var axi ...
随机推荐
- 2014.12.05(解决eclipse的adb打不开)
一.问题如下图所示 The connection to adb is down, and a severe error has occured.You must restart adb and Ecl ...
- HttpWebRequest:百度定位当前位置解析
HttpWebRequest request = (System.Net.HttpWebRequest)WebRequest.Create("http://api.map.baidu.com ...
- php中method_exists()和is_callable()如何进行语句判断
method_exists()和is_callable()方法进行判断.那么两则区别是什么呢? 已知类文件如下: class Student{private $alias=null;private $ ...
- java面试每日一题10
题目:利用递归方法求5! public class Recursion { public static void main(String args[]) throws NumberFormatExce ...
- JAVA导出数据到excel中大数据量的解决方法
最近在做项目功能时 ,发现有20万以上的数据.要求导出时直接导出成压缩包.原来的逻辑是使用poi导出到excel,他是操作对象集合然后将结果写到excel中. 使用poi等导出时,没有考虑数据量的问题 ...
- 杭电1020-Encoding
Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following ...
- ZOJ 3860: - Find the Spy
3860 - Find the Spy Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu S ...
- c# 财务数据编号的生辰
实现逻辑: 根据票号前戳+生成的6位数据编号=收据号(010+000001=010000001) 作废票号 将票号作废,插入到编号表中,以此下次在使用 作废票号使用 编号表中 现在只有2,当 ...
- openmp在图像处理上面的运用
// openmptest的测试程序 // #include "stdafx.h" void Test(int n){ for (int i=0;i<1000 ...
- UVa 10047,独轮车
题目链接:https://uva.onlinejudge.org/external/100/10047.pdf 题目链接:http://vjudge.net/contest/132239#proble ...