Comments (9)
这个jsHandler暂时没用到,用于后期的js调用oc的消息接受者指定,昨天一不小心提交了;后面会有用;现在属于垃圾代码;有其它问题也欢迎指出,一起学习,感谢!
from vdwebview.
已修复
from vdwebview.
@VolientDuan 现在可以拦截js方法吗?
from vdwebview.
可以的 demo中给出了示例方法
from vdwebview.
好像不能在不修改之前HTML代码的前提下,拦截js方法。比如之前使用context[@"js方法名"]
还望多多指教!
from vdwebview.
没理解你说的,你可以简单描述一下应用场景
from vdwebview.
function sendMessage() {
postMessage("这是我发给你的私信,别告诉别人哦")
}
想在OC中拦截postMessage,并把参数传递给OC。该如何做呢?
我看到您是用的是 window.webkit.messageHandlers。
from vdwebview.
我的理解是这样的,不知道是不是你想要的,
你可以通过js注入自定义方法,比如自定义的postMessage方法
OC方法
[self.webView addUserScriptWithSource:@"function postMessage(msg) { window.webkit.messageHandlers.postMessage.postMessage(msg)}" injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES];
// reload生效
[self.webView reload];
JS方法
function testPostMessage() {
// postMessage 为需要拦截的方法
postMessage("这是我发给你的私信,别告诉别人哦")
}
详细代码在demo中 可自行下载调试
from vdwebview.
好的,谢谢。
from vdwebview.
Related Issues (7)
- url加载不成功 HOT 1
- JS调OC,target-action回调方式无效 HOT 3
- 返回上一级报错 HOT 4
- contentHeight 获取时机 HOT 7
- demo中js调用OC方法无效 HOT 1
- bridge方法不支持返回值? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vdwebview.