为什么我的Mac应用程序中的WebView html拒绝加载JQuery或任何外部脚本
Why does the WebView html in my Mac app refuse to load JQuery or any external script?
我有一个简单的index.html文件,如下所示:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
setInterval(function(){
if (typeof Cocoa !== 'undefined') {
Cocoa.log('JQuery loaded...');
}
}, 3000);
});
</script>
</head>
<body>
<h1>Testing script in objective c enviroment.</h1>
<div id="container" class="col">
<p>Paragraph 1</p>
<p>content goes here</p>
</div>
</body>
</html>
从我的AppDelegate:中的WebView子类加载
appDelegate.h
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property NSWindow *webWindow;
@property myWebView *myWV;
@end
// ...
appDelegate.m
#import <WebKit/WebKit.h>
#import "myWebView.h"
@implementation AppDelegate
// ...
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
CGRect webRect = CGRectMake(0, 0, 1000, 1000);
self.webWindow = [[NSWindow alloc] initWithContentRect:webRect styleMask:NSTexturedBackgroundWindowMask backing:NSBackingStoreBuffered defer:NO];
self.webWindow.contentView = [[NSView alloc] initWithFrame:webRect];
self.myWV = [[myWebView alloc] initWithFrame:webRect frameName:@"myWV" groupName:@"webViews"];
self.myWV.UIDelegate = self;
self.myWV.resourceLoadDelegate = self;
self.myWV.frameLoadDelegate = self;
[self.webWindow.contentView addSubview:self.myWV];
[self.webWindow orderFront:NSApp];
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"index"
ofType:@"html"
inDirectory:@""];
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
NSURLRequest *request = [NSURLRequest requestWithURL:fileURL];
[[self.myWV mainFrame] loadRequest:request];
}
// associate js "Cocoa.log" function with -logJavaScriptString: method
+ (NSString *)webScriptNameForSelector:(SEL)sel
{
if(sel == @selector(logJavaScriptString:))
return @"log";
return nil;
}
//this allows JavaScript to call the -logJavaScriptString: method
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)sel
{
if(sel == @selector(logJavaScriptString:))
return NO;
return YES;
}
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
NSLog(@"webView loaded");
[[self.myWV windowScriptObject] setValue:self forKey:@"Cocoa"];
}
- (void)logJavaScriptString:(NSString *)logText
{
NSLog(@"JavaScript: %@",logText);
}
为什么$(function() {});
内部没有任何调用?如果我将interval log函数放在JQuery onReady函数之外,它确实会在几秒钟后开始调用正确的方法。
是否存在阻止加载脚本的跨站点策略问题?如果是,我如何禁用它?为什么jQuery没有加载?
我更改了
https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
至
http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
现在它起作用了。如果有人知道WebView
不喜欢https的原因,请在评论中告诉我。
相关文章:
- Ajax请求文档就绪会导致jquery加载缓慢
- jQuery加载的async和ready函数不工作
- jQuery加载完成事件不起作用
- jQuery加载方法字符集
- 使用jQuery加载页面上的配色方案
- 向使用jQuery加载DOM后添加的字段添加不受限制的文本输入DatePickers
- 我的jQuery加载请求是否被调用了两次
- jquery加载后会触发任何事件吗
- Jquery加载页面时的颜色更改效果
- 在AJAX jQuery加载()之后运行jQuery代码
- 使用jQuery加载页面时自动向上滚动
- 使用 jQuery 加载一系列图像
- 在 Wordpress 中调试 jquery 加载问题
- 使用 jQuery 加载 JSON,然后将其显示给查看器
- Jquery 加载的图像对类没有反应
- jquery加载时间和里面的css样式
- Rails:使用jQuery加载分部
- jQuery加载函数后,jQuery UI自动完成功能不起作用
- jQuery加载窗口,同时等待长函数完成
- "数据表”;jquery加载后CSS样式消失