Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

knut

macrumors newbie
Original poster
Jun 30, 2009
21
0
Hi All
In my web view I am loading local html(in viewDidLoad function)I have button on my webview too and in my button function i call js function .
1.load html
Code:
- (void)viewDidLoad { // load local html}
2.button function with timmer
Code:
-(IBAction) ButtonPress :(id) sender
{
  	timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(targetMethod:) userInfo: nil repeats: YES];
}

-(void) targetMethod:(NSTimer*) theTimer
{
   NSString *_script = @"window.location = 'some_value';"
}
after this when i change window.location is calling the next function where i do some action for example play some avi file but after my avi file is finished playing I lost my already loaded html.
Code:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
		if ( [request.mainDocumentURL.relativePath isEqualToString:@"/playSong/1"] ) { // do something}
return true;


}
can someone explain me this behavior? why i lost my html? i.e I lost the <span> with the text.
this is my ja code and my html
Code:
NSString *_script = @"var song_list = new Array('play/song1' , 'play/song2', 'play/song3' , 'play/song4' , 'play/song5');var pos = new Array(84,105,150,155);var row=document.getElementById('Text').innerHTML;var begin = document.getElementById('Text').innerHTML;var end = document.getElementById('RedText').innerHTML; var shift = begin.length + end.length;for(var i = 0;i <= pos.length; i++ ){var len = row.length;if(pos[i] == (shift - len) ){ window.location = '/playSong/1'; }}document.getElementById('RedText').innerHTML+=row.substr(0,1);document.getElementById('Text').innerHTML=row.replace(row.substr(0,1),'');";

html
Code:
<body>
        <span class="red" id="RedText"></span>
        
        <span id="Text"  >
           test test test test test test tset tset ste ste s.    
         </span>
            </br></br>
        <input type="button" onClick="start_1()"   style="width: 15em;"  value="start_first_speed" />
        
        <input type="button" onClick="start_2()"  style="width: 15em;" value="start_second_speed" />
        <input type="button" onClick="Stop()"  style="width: 15em;" value="stop" />
    </body>
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.