English 中文(简体)
客观项目中的javascript的读/正文文件
原标题:Read/write text file from javascript in objective-c project

我正在做一个 app子,当时,我正在利用 Java文把你带入“IDWebView”。 我想公开/阅读/准备从javascript开始的一些事件的档案,然后希望在客观法典中使用这一档案。 但我如何能够这样做? 我指的是我能够拯救和打开档案的地点。

我已经提交了一份名为“你”的档案,并将这一档案从客观的法典中删除。 该网页成功开放。 现在,我要开立案卷,每当它所描述的变化时写出一些东西,然后需要证明,最后是出于服从。 请告诉我,我如何能够这样做。

<!DOCTYPE HTML>
<html>
<body>
<div id="player"></div>
<script>
    //Load player api asynchronously.
    var tag = document.createElement( script );
    tag.src = "http://www.youtube.com/player_api";
    var firstScriptTag = document.getElementsByTagName( script )[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
    var done = false;
    var player;
    function onYouTubePlayerAPIReady() {
        player = new YT.Player( player , {
          height:  390 ,
          width:  640 ,
          videoId:  JW5meKfy3fY ,
          events: {
             onReady : onPlayerReady,
             onStateChange : onPlayerStateChange
          }
        });
    }
    function onPlayerReady(evt) {
        evt.target.playVideo();
    }
    function onPlayerStateChange(evt) {
        if (evt.data == YT.PlayerState.PLAYING && !done) { // NEED TO ADD FILE OPERATION HERE
            setTimeout(stopVideo, 6000);
            done = true;
        }
    }
    function stopVideo() {
        player.stopVideo();
    }
</script>
</body>
</html>

THanks Akansha

问题回答
// Get file path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString filePath = [documentsDirectory stringByAppendingPathComponent:filename];

// Read file contents
NSString *content = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

// Write file contents
[[content dataUsingEncoding:NSUTF8StringEncoding] writeToFile:filePath atomically:NO];

UIWebView is a sandbox, there is no chance to do this, javascript can not access file system directly, this is what i know. But you can do other thing. first: save state into window object;

such as window.state = "someting";

第二:按目标C改为国家;

NSString *state = [webView stringByEvaluatingJavaScriptFromString:@"window.state"];




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签