WKWebView - WKUserScript介绍4

2018-11-13  本文已影响5人  edison0428

WKUSSRcript对象表示可以注入到网页中的脚本
js的代码如下

1 initWithSource:injectionTime:forMainFrameOnly:

返回可添加到用户内容控制器的初始化用户脚本
参数1:脚本的源代码
参数2:脚本应注入网页的时间,是个枚举

1.WKUserScriptInjectionTimeAtDocumentStart:在创建文档元素之后,但在加载任何其他内容之前注入脚本
2.WKUserScriptInjectionTimeAtDocumentEnd:在文档完成加载之后,但在其他子资源完成加载之前插入脚本

参数3:是否加入所有框架,还是只加入主框架
injected only into the main frame (YES) or into all frames (NO)

属性
/* @abstract The script source code. */
@property (nonatomic, readonly, copy) NSString *source;

/* @abstract When the script should be injected. */
@property (nonatomic, readonly) WKUserScriptInjectionTime injectionTime;

/* @abstract Whether the script should be injected into all frames or just the main frame. */
@property (nonatomic, readonly, getter=isForMainFrameOnly) BOOL forMainFrameOnly;
上一篇下一篇

猜你喜欢

热点阅读