Ios 通过代码将参数传递给html
我已经创建了一个html,我想把它加载到我的webview中,并传递参数,即宽度、高度和视频idIos 通过代码将参数传递给html,ios,iframe,youtube-api,Ios,Iframe,Youtube Api,我已经创建了一个html,我想把它加载到我的webview中,并传递参数,即宽度、高度和视频id <html> <body> <script type='text/javascript' src="http://www.example.com/api"></script> <iframe id='player' type='text/html' width='%d' height='%d' src="http://www.youtube.c
<html>
<body>
<script type='text/javascript' src="http://www.example.com/api"></script>
<iframe id='player' type='text/html' width='%d' height='%d' src="http://www.youtube.com/embed/%@?enablejsapi=1&rel=0&playsinline=1" frameborder='0'>
<script type='text/javascript'>
..... my code/functions here
</script>
</body>
</html>
但它无法加载此html字符串
如果有人能帮我弄清楚的话。
提前感谢。我有一个类似的用例。它适用于我的
stringwithcontents文件:
这是我的代码:
NSString *htmlContent = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"youtube" ofType:@"html"] encoding:NSUTF8StringEncoding error:nil];
NSString *html = [NSString stringWithFormat:htmlContent, 320, 208, videoId];
[self.webView loadHTMLString:html baseURL:nil];
如果这不起作用,请记录生成的字符串
NSString *htmlContent = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"youtube" ofType:@"html"] encoding:NSUTF8StringEncoding error:nil];
NSString *html = [NSString stringWithFormat:htmlContent, 320, 208, videoId];
[self.webView loadHTMLString:html baseURL:nil];