-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug fix and remove file of webviewjavascript.js
- Loading branch information
1 parent
a4f66e5
commit c8f754a
Showing
17 changed files
with
258 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#### 版本更新说明 | ||
|
||
v1.0.0 | ||
|
||
1.重构JS桥代码以及引入BridgeTiny对象管理; | ||
2.支持X5内核的简单使用; | ||
3.简化项目集成难度; | ||
|
||
v1.0.1 | ||
|
||
1.修改JS注入方式,弃用assets文件读取,直接以字符串引入; | ||
2.修复1.0.0版本中WebViewJavascriptBridge.js以js脚本引入路径错误不生效问题, | ||
修改为直接使用webview.loadurl(javascript:str)方式插入H5中; | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<html> | ||
<head> | ||
<meta content="text/html; charset=utf-8" http-equiv="content-type" /> | ||
<!-- <script type="text/javascript" src="WebViewJavascriptBridge.js"></script>--> | ||
<title> | ||
js调用java | ||
</title> | ||
</head> | ||
|
||
<body> | ||
<p id="show"> | ||
|
||
</p> | ||
<p id="init"> | ||
|
||
</p> | ||
<p> | ||
<input type="text" id="text1" value="username"/> | ||
</p> | ||
<p> | ||
<input type="text" id="text2" value="password"/> | ||
</p> | ||
<p> | ||
<input type="button" id="enter" value="调用Native方法(请求)" onclick="testClick();" | ||
/> | ||
</p> | ||
<p> | ||
<input type="button" id="enter1" value="调用Native方法(Toast)" onclick="testClick1();" | ||
/> | ||
</p> | ||
<p> | ||
<input type="button" id="enter3" value="调用Native方法(高并发测试)" onclick="testClick2();" | ||
/> | ||
</p> | ||
</body> | ||
<script> | ||
|
||
function testClick() { | ||
var str1 = document.getElementById("text1").value; | ||
var str2 = document.getElementById("text2").value; | ||
|
||
var data = {url: 'www.baidu.com', userName: str1, passwd: str2}; | ||
window.WebViewJavascriptBridge.callHandler('request', | ||
data | ||
, function(responseData) { | ||
|
||
console.log('native return->'+responseData); | ||
} | ||
); | ||
} | ||
|
||
function testClick1() { | ||
var str1 = document.getElementById("text1").value; | ||
var str2 = document.getElementById("text2").value; | ||
//call native method | ||
window.WebViewJavascriptBridge.callHandler( | ||
'toast' | ||
, {'msg': '中文测试'} | ||
, function(responseData) { | ||
console.log('native return->'+responseData); | ||
} | ||
); | ||
} | ||
|
||
function testClick2() { | ||
|
||
|
||
var str1 = document.getElementById("text1").value; | ||
var str2 = document.getElementById("text2").value; | ||
var i = 0; | ||
var first = setInterval(function(){ | ||
//call native method | ||
window.WebViewJavascriptBridge.callHandler( | ||
'toast' | ||
, {'msg': '中文测试'} | ||
, function(responseData) { | ||
console.log('return->['+ i++ +']'+responseData); | ||
} | ||
); | ||
|
||
if(i>500){ | ||
clearInterval(first); | ||
} | ||
}, 10); | ||
|
||
} | ||
|
||
|
||
function bridgeLog(logContent) { | ||
document.getElementById("show").innerHTML = logContent; | ||
} | ||
|
||
function connectWebViewJavascriptBridge(callback) { | ||
if (window.WebViewJavascriptBridge) { | ||
callback(WebViewJavascriptBridge); | ||
} else { | ||
document.addEventListener( | ||
'WebViewJavascriptBridgeReady' | ||
, function() { | ||
callback(WebViewJavascriptBridge) | ||
}, | ||
false | ||
); | ||
} | ||
} | ||
|
||
connectWebViewJavascriptBridge(function(bridge) { | ||
bridge.init(function(message, responseCallback) { | ||
console.log('JS got a message', message); | ||
var data = { | ||
'Javascript Responds': '测试中文!' | ||
}; | ||
|
||
if (responseCallback) { | ||
console.log('JS responding with', data); | ||
responseCallback(data); | ||
} | ||
}); | ||
|
||
bridge.registerHandler("functionInJs", function(data, responseCallback) { | ||
document.getElementById("show").innerHTML = ("data from Java: = " + data); | ||
if (responseCallback) { | ||
var responseData = "Javascript Says Right back aka!"; | ||
responseCallback(responseData); | ||
} | ||
}); | ||
}) | ||
|
||
</script> | ||
|
||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 32 additions & 5 deletions
37
app/src/main/java/com/smallbuer/jsbridge/demo/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.