Ios 의 JavaScript 경고마다 대화 제목 변경

제목 '아이폰' 의 JavaScript 에서 위웹비에프 변경하십시오 경고마다 수 있습니까?

질문에 대한 의견 (3)
해결책

기본적으로 나는 늑대굴에서 보여주는 방식을 변경할 수 없습니다, 하지만 최근 직무명 대화 없이 경고를 하였다.

var iframe = document.createElement("IFRAME");
iframe.setAttribute("src", 'data:text/plain,');
document.documentElement.appendChild(iframe);
window.frames[0].window.alert('hello');
iframe.parentNode.removeChild(iframe);
해설 (6)

내가 세 가지 방법을 통해 이 문제를 해결할 수 있는. 가장 적합한 솔루션을 운영본 코드 중 하나는 설명자 @Martin H. 내 유일한 방법이 나와 함께 이 구체적 사례를 구현할 수 있습니다.

39 의 문서화되지 않은 비헤이비어를 달려 있지만, 내 다른 솔루션을 위웹비에프 don& 컨텐츠 / JS 변경할 필요가 없다.

  • 솔루션 1*: 이것은 이 기술을 통해 구체적인 예를 보여주는 그것으 동일팔레트에 의존하지 않으므로 위웹비에프 @Martin H. 이 최적의 솔루션을 보인다 '' / '루이 알레르비예프' 문서화되지 않은 비헤이비어를.
@interface TSViewController () 
@end

@implementation TSViewController

- (UIWebView*) webView
{
    return (UIWebView*) self.view;
}

- (void) loadView
{
    UIWebView* wv = [[UIWebView alloc] initWithFrame: CGRectMake(0, 0, 320, 480)];
    wv.delegate = self;
    wv.scalesPageToFit = YES;

    self.view = wv;
}

- (void) viewDidLoad
{
    [super viewDidLoad];

    [self.webView loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString: @"http://www.craigslist.org"]]];
}

- (void) webViewDidFinishLoad: (UIWebView *) webView
{
    // inject some js to re-map window.alert()
    // ideally just do this in the html/js itself if you have control of that.
    NSString* js = @"window.alert = function(message) { window.location = \"http://action/alert?message=\" + message; }";
    [webView stringByEvaluatingJavaScriptFromString: js];

    // trigger an alert.  for demonstration only:
    [webView stringByEvaluatingJavaScriptFromString: @"alert('hello, world');" ];
}

- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL* url = request.URL;

    // look for our custom action to come through:
    if ( [url.host isEqualToString: @"action"] && [url.path isEqualToString: @"/alert"] )
    {
        // parse out the message
        NSString* message = [[[[url query] componentsSeparatedByString: @"="] lastObject] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        // show our alert
        UIAlertView* av = [[UIAlertView alloc] initWithTitle: @"My Custom Title"
                                                     message: message
                                                    delegate: nil
                                           cancelButtonTitle: @"OK"
                                           otherButtonTitles: nil];

        [av show];

        return NO;
    }
    return YES;
}
  • 솔루션 2: 나라면 절대 먼저 말하고, 나한테 직접 운영 솔루션을 사용할 수 있는 최선의 방법은 이 기능은 다음 code.* 이룹니까 해야할 @Martin H 의 경우, 또는 기타 어떤 @twk 제안됩니다 그의 답변은 제안됩니다 빈 직무명 실제로 어떤 필요에 의해. # 39, 웹 콘텐츠 자체가 don& 제어할 수 없는 경우, 그 후, 코드 s # 39 컨텐트에서 로드되었는지 H& @Martin 투입할 수 있습니다.

이 경우, 그렇지 않으면 우리가 할 수 있는 몇 가지 가정을 것 "이라고 말했다. 첫째, Javascript '경고' 진짜 '루이 알레르비예프 랑하니 매핑됨 하는 방법 ()'. (사실 않니다!) 둘째, 분별할 수 있는 몇 가지 메커니즘이 직면할 수 있음을 알 수 있습니다 '경고' 에서 '우리아르트비우스 응용 프로그램 공급 루이 알레르비예프 공급 ()' '다른'. (We can!)

이 방식은 루이 알레르비예프 뒤섞다 '내'. 그러니까말이야 - 스위 즐링 그것은됐다 계시한하나님께 온갖 문제점이. # 39, t 뒤섞다 수 있다면 좋겠지만, 내가 don& 생산 앱을 통해 it. 그러나 이 과학 프로젝트 '를' re going, 뒤섞다 we& # 39 를 루이 알레르비예프 세드리게이트 메서드입니다.

내가 찾은 것은 1) 이 '위웹비에프 chunghwa' 은 '한' 루이 알레르비예프 표시하십시오 javascript 경고 및 2) '이' 제목 '전에 설정되었습니다 루이 알레르비예프 루이 알레르비예프 위임합니다' 설정되었습니다. 내가 내 스스로 수행할 수 있는 방법을 통해 루이 알레르비예프 세드리게이트 스위 즐링 '' 두 가지. 1) '의' 내가 할 수 있는 '루이 알레르비예프 사항결정 대신인지 의뢰한 중입니다 위웹비에프' (그냥 위임합니다 검사합니다.) 2) I 기회가 다시 놓기 전에 제목 알레르비예프 볼 수 있습니다.

그냥 쇼 ',' 루이 알레르비예프 뒤섞다 왜안돼요 &quot 하나님께용서를 수 있습니다 - 내 실험 방법 - &quot 잘하는 것은 아니지만, 될 수 있는 '쇼' 호출되었을 위웹비에프 내가 찾은 적이 없다. # 39, 기타 다른 내부 메서드를 호출하는 비활성화해야 쉐퍼드도 didn& 보다 자세히 조사할 수 없다.

내 솔루션을 구현할 수 있는 몇 가지 클래스에 대한 범주입니다 루이 알레르비예프 자도으로 방법. 이러한 방법을 통해 실행할 수 있는 위웹비에프 장부를요 교체품을 제공하십시오 직무명 사용할 수 있습니다. 또는 블록의 호출되었을 때 제목을 되돌려줍니다 콜백하는 제공할 수 있습니다.

난 계속 사용한 일련의 위웹비에프 하였다 ios6 산마프터블 '클래스' 는 약한 매핑이라는 위웹비에프 있는 주요. 이렇게 내가 갖게 하고, 내 모든 것을 '와' 위웹비에프 don& # 39 가 아주 잘 복구하였습니다 등록을 취소할 수 없다. 이 때문에 현재 구현은 iOS6-only.

39, 코드 s 에서 보는 바와 같이 기본적인 보기를 컨트롤러거 here& 사용 중.

#import 

typedef NSString*(^TSAlertTitleBlock)(UIWebView* webView, NSString* defaultTitle );

@interface UIAlertView (TS)
@end

@implementation UIAlertView (TS)

NSMapTable* g_webViewMapTable;

+ (void) registerWebView: (UIWebView*) webView alertTitleStringOrBlock: (id) stringOrBlock
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{

        g_webViewMapTable = [NSMapTable weakToStrongObjectsMapTable];

        // $wizzle
        Method originalMethod = class_getInstanceMethod(self, @selector(setDelegate:));
        Method overrideMethod = class_getInstanceMethod(self, @selector(setDelegate_ts:));
        method_exchangeImplementations(originalMethod, overrideMethod);
    });

    [g_webViewMapTable setObject: [stringOrBlock copy] forKey: webView];
}

+ (void) registerWebView: (UIWebView*) webView alertTitle: (NSString*) title
{
    [self registerWebView: webView alertTitleStringOrBlock: title];
}

+ (void) registerWebView: (UIWebView*) webView alertTitleBlock: (TSAlertTitleBlock) alertTitleBlock
{
    [self registerWebView: webView alertTitleStringOrBlock: alertTitleBlock];
}

- (void) setDelegate_ts: (id) delegate
{
    // call the original implementation
    [self setDelegate_ts: delegate];

    // oooh - is a UIWebView asking for this UIAlertView????
    if ( [delegate isKindOfClass: [UIWebView class]] )
    {
        // see if we've registered a title/title-block
        for ( UIWebView* wv in g_webViewMapTable.keyEnumerator )
        {
            if ( wv != delegate)
                continue;

            id stringOrBlock = [g_webViewMapTable objectForKey: wv];

            if ( [stringOrBlock isKindOfClass: NSClassFromString( @"NSBlock" )] )
            {
                stringOrBlock = ((TSAlertTitleBlock)stringOrBlock)( wv, self.title );
            }

            NSParameterAssert( [stringOrBlock isKindOfClass: [NSString class]] );

            [self setTitle: stringOrBlock];
            break;
        }
    }
}

@end

@interface TSViewController () 
@end

@implementation TSViewController

- (UIWebView*) webView
{
    return (UIWebView*) self.view;
}

- (void) loadView
{
    UIWebView* wv = [[UIWebView alloc] initWithFrame: CGRectMake(0, 0, 320, 480)];
    wv.delegate = self;
    wv.scalesPageToFit = YES;

    self.view = wv;
}

- (void) viewDidLoad
{
    [super viewDidLoad];

    // method 1: bind a title to a webview:
    [UIAlertView registerWebView: self.webView alertTitle: nil];

    /*
    // method 2: return a title each time it's needed:
    [UIAlertView registerWebView: self.webView
                 alertTitleBlock: ^NSString *(UIWebView *webView, NSString* defaultTitle) {

                     return @"Custom Title";
    }];
     */

    [self.webView loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString: @"http://www.craigslist.org"]]];
}

- (void) webViewDidFinishLoad: (UIWebView *) webView
{
    // trigger an alert
    [webView stringByEvaluatingJavaScriptFromString: @"alert('hello, world');" ];
}

@end
  • 솔루션 3*: # 39 의 반사, here& 빛위에 단순한 기법을 설명한 나보다 먼저 해결 방법 2. 그래도 문서화되지 않은 사실에 따라 javascript 경보는 루이 알레르비예프 사용하여 있는 위임합니다 소싱 위웹비에프 설정되었습니다 구현됩니까 있다. 이를 위해 솔루션 및 구축, 단순히 자신의 하위 위웹비에프 위임합니다 방법, 언제, 어떤 제목을 재설정하십시오 프로파일링하려는 루이 알레르비예프 윌프레센탈레르비예프 호출됩니다.
@interface TSWebView : UIWebView
@end

@implementation TSWebView

- (void) willPresentAlertView:(UIAlertView *)alertView
{
    if ( [self.superclass instancesRespondToSelector: @selector( willPresentAlertView:) ])
    {
        [super performSelector: @selector( willPresentAlertView:) withObject: alertView];
    }

    alertView.title = @"My Custom Title";
}

@end

@interface TSViewController () 
@end

@implementation TSViewController

- (UIWebView*) webView
{
    return (UIWebView*) self.view;
}

- (void) loadView
{
    UIWebView* wv = [[TSWebView alloc] initWithFrame: CGRectMake(0, 0, 320, 480)];
    wv.delegate = self;
    wv.scalesPageToFit = YES;

    self.view = wv;
}

- (void) viewDidLoad
{
    [super viewDidLoad];

    [self.webView loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString: @"http://www.craigslist.org"]]];
}

- (void) webViewDidFinishLoad: (UIWebView *) webView
{
    // trigger an alert
    [webView stringByEvaluatingJavaScriptFromString: @"alert('hello, world');" ];
}

@end
해설 (6)

39, no you can& Javascript 경고를 이 작업을 수행할 수 없다.

만일 당신의 다음 Javascript 가 아닌 호출하는 함수를 호출하는 대신 사용할 수 있는 객관적인 C 와 iOS lan-alert 호출하십시오 호출하십시오 넷윈을 걸렸다.

39 를 사용하여 Javascript isn& 경우, 다음 네 t 위웹비에프 무시하려면 기본 실행 및 일부 자금을 투입할 수 있는 iOS 호출하십시오 Javascript 변경하십시오 넷윈을 경고마다 즉, 이 같은 일이

window.alert = function(message) {
  window.location = "myScheme://" + message"
};

39 의 서우두스타르로트비토리퀘스트 UIWebView& 푸십시오 미셸메 및 메시지에 대한 보세요

39 의 Javascript 에서 된 오브젝티브 here& 표준 방법

https://stackoverflow.com/questions/1662473/how-to-call-objective-c-from-javascript

해설 (0)

39, s worth, 코르도바 뭐하러요 it& 폰갭 / 는 [나비가토리노리피카션드라이트] (http://docs.phonegap.com/en/edge/cordova_notification_notification.md.html # 노아피카션드라이트) 함수. 따라서 specifying 사용자 정의 하였다.

해설 (0)

그냥 단축시킵니다 위웹비에프 저회가 윌프레센탈레르비예프 (make a 클래스 (알레르비예프: 루이 알레르비예프) 함수 항목이없습니다. 그 후, 정보기술 (it), '세트' 알레르비우스티리 그러하매 너희의 즐겨 찾기 = &quot title&quot 완료되어도.

    import UIKit

class webviewClass: UIWebView {

func willPresentAlertView(alertView: UIAlertView) {

    alertView.title = "my custum title"
}

}

그 후 판매업체에서 때 알림 또는 확인하고. 사용자 지정 제목은 볼 수 있습니다.

해설 (0)

내가 그냥 경보 기능은 덮어씁니다 끄기도구 뭐한테 @twk 것 같다 "고 썼다. 작동됨 멋지구리해요 켜짐이 ios7.

function alert(words){
var iframe = document.createElement("IFRAME");
iframe.setAttribute("src", 'data:text/plain,');
document.documentElement.appendChild(iframe);
window.frames[0].window.alert(words);
iframe.parentNode.removeChild(iframe);
}
해설 (1)

코르도바 플러그인에는 대화상자의 사용합니다. 넷윈을 대화상자의 만들 수 있습니다.

아래 코드를 작성하고 넷윈을 경고:

navigator.notification.alert(message, alertCallback, [title], [buttonName])
해설 (0)