Develop
2015.02.10 18:08
[ios] 로컬에 있는 JS 파일 웹뷰에서 동적으로 실행하기
조회 수 958 댓글 0
JS 파일을 프로젝트로 추가하고 UIWebView 딜리게이트를 처리하는 내용
- (void)webViewDidStartLoad:(UIWebView *)webView{ ... // JS파일들을 동적으로 추가하는 내용의 함수 호출 [self injectJSCodes]; } - (void)webViewDidFinishLoad:(UIWebView *)webView { .... // JS 함수가 잘 로드되고 실행 되는지 확인 NSString *jsString1 = @"picomax.alert('2100411931200932');"; [_webView stringByEvaluatingJavaScriptFromString:jsString1]; NSString *jsString2 = @"OcbiOSJS.showBarcodeScanPopup('2100411931200932');"; [_webView stringByEvaluatingJavaScriptFromString:jsString2]; } - (void)injectJSWithPath:(NSString *)path { //현재 프로젝트의 리소스 파일의 경로 얻기. //NSString *resourcePath = [[NSBundle mainBundle] resourcePath]; //NSString *path = [[NSBundle mainBundle] pathForResource:@"OcbiOSJS" ofType:@"js"]; NSLog(@"js path : %@", path); NSString *jsString = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; [_webView stringByEvaluatingJavaScriptFromString:jsString]; } - (void)injectJSCodes { [self injectJSWithPath:[[NSBundle mainBundle] pathForResource:@"OcbiOSJS" ofType:@"js"]]; [self injectJSWithPath:[[NSBundle mainBundle] pathForResource:@"OcbiOSTitleViewJS" ofType:@"js"]]; }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
729 | Develop | [js] 양원님이 공유해 주신 유료(5$란다ㅋ) 자료 ㅋㅋ | hooni | 2013.04.23 | 7948 |
728 | Develop | [js] 실행되는 디렉토리 확인하는 스크립트.. | hooni | 2013.04.23 | 6766 |
727 | Develop | [js] 스타크래프트(starcraft).. | hooni | 2013.04.23 | 6641 |
726 | Develop | [js] 스크롤을 포함한 마우스 위치 찾는 코드 | hooni | 2003.04.23 | 8505 |
725 | Develop | [js] 스크롤 이벤트 막기 | hooni | 2015.04.14 | 1013 |
724 | Develop | [js] 숫자만 입력하게 하는 자바스크립트 | hooni | 2013.04.23 | 6798 |
723 | Develop | [js] 순환참조에 의한 메모리 누수 관련 | hooni | 2013.12.17 | 10846 |
722 | Develop | [js] 수학 공식을 제공하는 Math 객체 | hooni | 2013.04.23 | 15415 |
721 | Develop | [js] 수명체크 프로그램 ㅋㅋ | hooni | 2013.04.23 | 6840 |
720 | Develop | [js] 셀렉트박스(select)의 옵션(option) 동적으로 추가/제거 | hooni | 2013.04.23 | 8061 |
719 | Develop | [js] 서서히 나타나는 화면.. ㅋㅋ | hooni | 2013.04.23 | 6196 |
718 | Develop | [js] 새로고침(refresh)방법과 다른 페이지 바꾸기.. | hooni | 2003.04.23 | 6521 |