私はMacの世界の初心者です。
Web ページに入力された情報をテキスト フィールドから抽出できるアプリを作成する必要があります。私のアプリは、どこかでホストされている Web ページを読み込みます。Web ページ内には、一連のテキスト フィールドと送信ボタンがあります。ボタンをクリックすると、この Web ページのテキスト フィールドに入力された情報を読み取ることができなければなりません。
私は次のようなコードを持っています:
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
{
// For security, you must explicitly allow a selector to be called from JavaScript.
if (aSelector == @selector(showMessage:)) {
return NO; // i.e. showMessage: is NOT _excluded_ from scripting, so it can be called.
}
return YES; // disallow everything else
}
- (void)showMessage:(NSString *)message
{
// This method is called from the JavaScript "onClick" handler of the INPUT element
// in the HTML. This shows you how to have HTML form elements call Cocoa methods.
DOMDocument *myDOMDocument = [[webView mainFrame] DOMDocument]; // 3
DOMElement *contentTitle = [myDOMDocument getElementById:@"TexTest"]; // DOM
message = [[contentTitle firstChild] nodeValue]; // lines
NSRunAlertPanel(@"Message from JavaScript", message, nil, nil, nil);
}
アプリを実行して NSRunAlertPanel に到達すると、それ以上実行したくありません。
3 つの DOM 行をコメントアウトすると、NSRunAlertPanel にメッセージが表示され、続行できます。
HTML は次のようになります。
<body>
<h1 id="contentTitle">Some kind of title</h1>
<div id="main_content">
<p>Some content</p>
<p>Some more content</p>
</div>
<div>
<input id="TexTest" value=" " type="text">
</div>
<div>
<input id="message_button" value="Show Message" onclick="window.AppController.showMessage_('Hello there...');" type="button">
</div>
</body>
この問題を手伝ってくれる人はいますか?