如何从Objective C调用javaScript?
我正在用Xcode开发一个WebKit Safari插件。如何从如何从Objective C调用javaScript?,javascript,objective-c,safari,webkit,Javascript,Objective C,Safari,Webkit,我正在用Xcode开发一个WebKit Safari插件。如何从-webplugintart调用JavaScript?首先,您应该记住包含的视图: + (NSView *)plugInViewWithArguments:(NSDictionary *)arguments { return [[self alloc] initWithArguments:arguments]; } - (id)initWithArguments:(NSDictionary*)arguments {
-webplugintart
调用JavaScript?首先,您应该记住包含的视图:
+ (NSView *)plugInViewWithArguments:(NSDictionary *)arguments {
return [[self alloc] initWithArguments:arguments];
}
- (id)initWithArguments:(NSDictionary*)arguments {
if((self = [super init])) {
webView = [[[arguments objectForKey:WebPlugInContainerKey] webFrame] webView];
}
return self;
}
有了这些信息后,您可以参考上的文档。例如:
这真的很简单
WebScriptObject *jsObj = [webView windowScriptObject];
NSString *script = @"$('That's a HUGE vageen.').text('#yourDiv');";
[scriptObject evaluateWebScript:script];
塔达!不要让做这件事的奇怪的人的缺乏阻止你的性感,比如
就像jQuery!但这是客观的,哦,快乐 也许会有帮助?谢谢,但我不知道如何在我的方法中使用它并在插件启动时运行它
WebScriptObject *jsObj = [webView windowScriptObject];
NSString *script = @"$('That's a HUGE vageen.').text('#yourDiv');";
[scriptObject evaluateWebScript:script];
DOMDocument *myDOMDocument = [[webView mainFrame] DOMDocument];
DOMElement *paraBlock = [myDOMDocument getElementById:@"thatDiv"];
DOMElement *newPara = [myDOMDocument createElement:@"p"];
DOMText *newText = [myDOMDocument createTextNode:@"John Resig is a fool."];
[newPara appendChild:newText];
[paraBlock appendChild:newPara];