如何更改在(Safari)iPhone中的window.alert(「消息」)彈出窗口中出現的標題(通常是域)?在safari(iPhone)中彈出警報
4
A
回答
5
您需要使用開源框架PhoneGap(http://www.phonegap.com/)。
然後,使用:
navigator.notification.alert("message", callback, "title", "button title");
通過JavaScript。
編輯:這隻會用於開發一個Web應用程序,而不是一個網站。更改警報標題是不可能的。
2
您可以使用適用於桌面/瀏覽器測試環境和PhoneGap/Native環境的通用版本。這裏是我工作:
function showMessage(message, title, callback, buttonName){
title = title || "";
buttonName = buttonName || 'OK';
if(navigator.notification){
navigator.notification.alert(
message, // message
callback, // callback
title, // title
buttonName // buttonName
);
}else{
alert(message);
if(callback)
callback();
}
}
0
任何人想要做到這一點沒有的PhoneGap框架,您可以將數據傳遞到iOS,然後顯示一個警告。
在你的WebView委託:
- (BOOL) webView:(UIWebView*)webView
shouldStartLoadWithRequest:(NSURLRequest*)request
navigationType:(UIWebViewNavigationType)type {
NSURL* url = [request URL];
NSString* scheme;
NSString* host;
NSString* path;
BOOL isRealUrl = YES;
switch (type) {
case UIWebViewNavigationTypeLinkClicked:
// Open link in Safari
[[UIApplication sharedApplication] openURL:url];
return NO;
break;
case UIWebViewNavigationTypeFormSubmitted:
case UIWebViewNavigationTypeOther:
scheme = [url scheme];
host = [url host];
path = [url path];
if ([scheme isEqualToString:@"alert"]) {
[[[UIAlertView alloc] initWithTitle:host
message:[path substringFromIndex:1]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
isRealUrl = NO;
} else {
// Go to another page in your app.
isRealUrl = YES;
}
break;
default:
break;
}
return isRealUrl;
}
在你的JavaScript:
function myAlert(message, title) {
if (/iphone|ipod|ipad/.test(navigator.userAgent) &&
!/safari/i.test(navigator.userAgent)) {
document.location.href = 'alert://' + encodeURIComponent(title) + '/' +
encodeURIComponent(message);
} else {
alert(message);
}
}
然後調用報警功能myAlert('Testing', 'One, Two, Three');
通知,該方案alert
必須委託函數和匹配javascript href。
相關問題
- 1. 水豚硒導航到網址在Safari上彈出警報
- 2. 警報出現在iPhone
- 3. JQuery彈出/警報需要
- 4. Chrome塊警報彈出
- 5. 如何在iPhone上的HTTP連接失敗時彈出警報?
- 6. 在選定之前彈出Javascript警報
- 7. ASP中的彈出式警報
- 8. iPhone在被盜時發出警報
- 9. Selenium IDE沒有捕獲彈出/警報
- 10. 從UIAlertView彈出查看警報
- 11. 阿賈克斯彈出警報
- 12. UiAutomator Android不識別警報彈出
- 13. 警報對話框彈出後期
- 14. 彈出警報或消息給用戶
- 15. 如何彈出報警聲選擇器
- 16. 圖像點擊彈出警報。
- 17. Android:執行計算時彈出警報
- 18. 彈出之前刪除警報框
- 19. Javascript timed彈出警報與位置.href
- 20. react-s-alert,警報不會彈出
- 21. 警報彈出如果裝置離線
- 22. LocationListener警報對話框彈出多個彈出框
- 23. 從c#彈出彈出警報消息頁
- 24. 打在iphone報警與EKEvent
- 25. iPhone中的警報視圖
- 26. 'undefined'出現在警報中
- 27. 彈出式窗口或警報彈出後彈出按鈕卡住
- 28. iPhone內存警報
- 29. 如何處理在自動化過程中彈出的警報?
- 30. 如何處理在Selenium中彈出的IE安全警報
那麼你不能爲任何普通的瀏覽器做到這一點,所以我打賭你不能爲iPhone瀏覽器做到這一點。 – epascarello 2010-11-02 12:33:41