unknown webview behavior

Discussion in 'iOS Programming' started by knut, Oct 5, 2009.

  1. knut macrumors newbie

    Jun 30, 2009
    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
    - (void)viewDidLoad { // load local html}
    2.button function with timmer
    -(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.
    - (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
    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),'');";
            <span class="red" id="RedText"></span>
            <span id="Text"  >
               test test test test test test tset tset ste ste s.    
            <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" />
  2. knut thread starter macrumors newbie

    Jun 30, 2009

Share This Page