简体   繁体   English

从网页控制UIWebView

[英]Control UIWebView from the web page

How can I control the UIWebView in an iOS app from the web page? 如何从网页控制iOS应用程序中的UIWebView?

For example, I want to resize it - not by setting the UIWebView's frame (in the Objective C code), but with some Javascript code, like window.resizeTo() 例如,我想调整它的大小-不是通过设置UIWebView的框架(在Objective C代码中),而是使用一些Javascript代码,例如window.resizeTo()

I've heard that I should implement a class that enables external control on the UIWebView. 我听说我应该实现一个类,以在UIWebView上启用外部控制。 Does anyone know which class is it? 有人知道这是哪门课吗?

Thanks, Keren 谢谢,可人

Check out lines 26-45 in this class. 在本课程中查看第26-45行。

https://github.com/trailbehind/Map-Chat/blob/master/Classes/ChatViewController.m https://github.com/trailbehind/Map-Chat/blob/master/Classes/ChatViewController.m

Is that what you are looking for? 那是您要找的东西吗?

I was using a UIWebView within a chat app. 我在聊天应用程序中使用的是UIWebView。 You can basically make a UIWebView do any JavaScript you want. 您基本上可以使UIWebView执行您想要的任何JavaScript。

Two things you can look at: 您可以看两件事:

  • the UIWebView method stringByEvaluatingJavaScriptFromString UIWebView方法stringByEvaluatingJavaScriptFromString

  • the UIWebView Delegate Protocol Reference, especially the webView:shouldStartLoadWithRequest method UIWebView委托协议参考,尤其是webView:shouldStartLoadWithRequest方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM