【问题标题】:Pass parameters to html through code通过代码将参数传递给html
【发布时间】:2014-04-09 05:45:02
【问题描述】:

我创建了一个 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.com/embed/%@?enablejsapi=1&rel=0&playsinline=1" frameborder='0'>
<script type='text/javascript'>

     ..... my code/functions here

</script>
</body>
</html>

现在,我在代码中写的是 -

NSString* html = nil;
NSString *htmlContent = [[NSString alloc] initWithContentsOfURL:[NSURL fileURLWithPath:youTubeHTMLFilePath] encoding:NSUTF8StringEncoding error:&error];


html = [NSString stringWithFormat:htmlContent, 320, 208, videoId];
[self.myWebview loadHTMLString:html baseURL:nil]; 

但它无法加载这个 html 字符串。

如果有人能帮我弄清楚,请。 提前致谢。

【问题讨论】:

    标签: ios iframe youtube-api


    【解决方案1】:

    我有一个类似的用例。它适用于stringWithContentsOfFile:
    这是我的代码:

    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];
    

    如果这不起作用,请记录生成的字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-29
      • 1970-01-01
      • 2021-07-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多