//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//팝업창을 자신의 webview위에 덮어 씌운다.
_web = (WebView)view.findViewById(R.id.web); // 레이아웃에 설정된 webview를 가져온다
_web.dispatchWindowFocusChanged(true);
_web.dispatchSetSelected(true);
_web.setFocusable(true);
_web.setFocusableInTouchMode(false);
_web.setVerticalFadingEdgeEnabled(true);
_web.setVerticalScrollBarEnabled(true);
_web.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
_web.getSettings().setJavaScriptEnabled(true);
_web.getSettings().setSupportMultipleWindows(true);
_web.getSettings().setGeolocationEnabled(true);
_web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
_web.getSettings().setBuiltInZoomControls(true);
_web.setWebViewClient(new WebViewClient());
_web.setWebChromeClient(new WebChromeClient() {
@Override public boolean onCreateWindow(
WebView view, boolean dialog, boolean userGesture, android.os.Message resultMsg
) {
view.removeAllViews();
WebView childView = new WebView(view.getContext());
childView.getSettings().setJavaScriptEnabled(true);
childView.setWebChromeClient(this);
childView.setWebViewClient(new WebViewClient());
childView.setLayoutParams(
new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)
);
view.addView(childView);
WebView.WebViewTransport transport = (WebView.WebViewTransport)resultMsg.obj;
transport.setWebView(childView);
resultMsg.sendToTarget();
return true;
}
});
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
출처: https://code.google.com/p/android/issues/detail?id=12145
Steps to reproduce this problem as simply as possible:
1) Modify the android browser to only use one tab (instead of filling up all tabs) to
quicken the process
2) Modify android browser to not use an error dialog and instead open new window in current
tab (I'd argue this needs to be done any time the browser tries to open a new window with
no tabs available).
3) Start up news.google.com and click on an article (tries to open a window) and
watch it crash due to a null pointer exception in WebViewCore.
The correct behavior should be that it uses the current tab to display what would be
a new window thereby appending this new url to the current history stack.
It seems that WebViewCore.transferMessages() is being called with mMessage == null.
As a quick fix, change the end of the function in the synchronized block:
synchronized (this) {
int size = mMessages.size();
for (int i = 0; i < size; i++) {
mHandler.sendMessage(mMessages.get(i));
}
mMessages = null;
}
to:
synchronized (this) {
if (mMessages != null) {
int size = mMessages.size();
for (int i = 0; i < size; i++) {
mHandler.sendMessage(mMessages.get(i));
}
mMessages = null;
}
}
I'd commit it myself, but I still don't have a signed agreement by my company. *sigh*
It also appears that no null check is made in Head either, so this might need to be
added for 2.2 and forward, but I haven't tested.
Oct 25, 2010
#1 herri...@gmail.comI just noticed that the browsing history isn't saved with this change. I'll update with a better implementation later.
Oct 26, 2010
#2 herri...@gmail.comOk, so to fix the browser history issue assuming you follow the above, just modify
frameworks/base/core/java/android/webkit/CallbackProxy.java:public WebView createWindow(boolean dialog, boolean userGesture):
WebView w = transport.getWebView();
if (w != null) {
w.getWebViewCore().initializeSubwindow();
}
return w;
to:
WebView w = transport.getWebView();
if (w != mWebView) {
if (w != null) {
w.getWebViewCore().initializeSubwindow();
}
}
return w;
Nov 2, 2010
#3 herri...@gmail.comThere may be further history stack issues associated with this.
Jan 11, 2012
#4 jeansguy...@gmail.comNullPointerException is caused when we reuse a webview in onCreateWindow. I implemented following workaround Instead of webview, use a ViewGroup in the screen layout, give it the same layout parameters (location, size etc) as you gave the webview (mWebViewPopup).
@Override
public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture,
android.os.Message resultMsg)
{
contentContainer.removeAllViews();
WebView childView = new WebView(mContext);
childView.getSettings().setJavaScriptEnabled(true);
childView.setWebChromeClient(this);
childView.setWebViewClient(new WebViewClient());
childView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
contentContainer.addView(childView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(childView);
resultMsg.sendToTarget();
return true;
}
in the above code
1) I have set layout parameters so that my web views fills the parent, you should use layout parameters as per your requirement.
2) mContext => context object
3) contentContainer => viewgroup which was declared in XML intended to contain the web view This is not clean but solves the problem.
Jun 23, 2013
#5 jbq@android.comBased on its date, this issue was originally reported before Android 4.x. Because of the many changes that existed in Android 4.x compared to previous versions, it's very likely that this issue doesn't exist in recent versions of Android like 4.2.2 or newer. Because of the high likelihood that this issue is obsolete, it is getting closed automatically by a script, without a human looking at it in detail. If the issue still exists on a Nexus 4 or Nexus 7 running Android 4.2.2 and is not related to Google applications, please open a new report accordingly.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void setWebViewSetting() { webView.setWebViewClient(new WebViewClient()); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, android.os.Message resultMsg) {
WebView newWebView = new WebView(MainActivity.this); view.addView(newWebView); WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj; transport.setWebView(newWebView); resultMsg.sendToTarget();
return true; }; public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result) { new AlertDialog.Builder(MainActivity.this) .setTitle("AlertDialog") .setMessage(message) .setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { result.confirm(); } }) .setCancelable(false) .create() .show();
return true; }; });
WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true);
/// webSettings.setBuiltInZoomControls(true); webSettings.setSupportZoom(true);
webSettings.setPluginState(WebSettings.PluginState.ON_DEMAND); webSettings.setSupportMultipleWindows(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setBlockNetworkImage(false); webSettings.setLoadsImagesAutomatically(true); webSettings.setUseWideViewPort(true); webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); |
웹뷰 어플을 만들고 있는 왕왕초보입니다.
어플내에서 새창을 띄워야 하는데 (주소 입력 하는것 아시죠?) 소스를 위에처럼 입력했더니
어플내에서가 아니라 외부 팝업창으로 뜹니다. 입력후에도 창이 닫히지 않고 어플내로 입력도 안되네요
구글링으로 어찌어찌 해당 소스까지는 왔는데 더이상은 찾아도 없는듯하고 봐도 솔직히 잘 모르겠네요 ㅜㅜ
웹사이트가 제가 직접 만든게 아니라 사이트내의 window.open 소스를 수정할 수는 없습니다.
1. 어플내에서 새창을 띄우기
2. 입력값을 다시 부모페이지로 입력 (새창은 닫힘)
이게 문제인데 저 소스에서 어떤 부분을 수정해야 할지 좀 알려주세요 고수님들
맨티스 (160 포인트) 님이 2015년 4월 6일 질문
newWebView에 setWebChromeClient하나 더 만들어주시고.
추가한 WebChromeClient에
@Override
public void onCloseWindow(WebView window) {
window.setVisibility(View.GONE);
메인웹뷰.removeView(window);
}
추가해서 처리해 주세요.
그리고 뒤로 가기버튼 시에도 추가한 뷰(팝업)을 제거해줘야 하기때무에
backkey이벤트 잡아서 추가한 뷰가 있으면 removeView를 해주셔야 합니다.
이드로이드 (22,930 포인트) 님이 2015년 4월 6일 답변
WebView newWebView = new WebView(MainActivity.this);
newWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onCloseWindow(WebView window) {
window.setVisibility(View.GONE);
메인웹뷰.removeView(window);
}
});
메인웹뷰.addView(newWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
출처: http://jo.centis1504.net/?p=1664
WebView에서의 멀티뷰와 팝업
setJavaScriptCanOpenWindowsAutomatically와 setSupportMultipleWindows메소드가 있다.
둘의 차이점을 조사해본 결과 아래와 같음.
setJavaScriptCanOpenWindowsAutomaticallysetSupportMultipleWindowstarget=”_blank”(태그)window.open(자바스크립트)비고
true | true | 반응없음 | OK | onCreateWindow메소드가 호출됨 |
true | false | OK | OK | |
false | true | 반응없음 | OK | onCreateWindow메소드가 호출됨 |
false | false | OK | OK 단 Android2.3에서는 뒤로가기가 안됨 |
위에서 OK의 경우는 현재의 WebView에 새창의 내용이 덮어씌어지는 경우를 뜻한다.
이상의 결과를 보면 스스로 멀티탭을 구현하는 경우는 setSupportMultipleWindows(true)로 하여
WebChromeClient클래스의 onCreateWindow메소드를 오버라이드한다.
여기에서 멀티탭이 열리고 애니메이션등등을 구현하면 되겠다.
setJavaScriptCanOpenWindowsAutomatically의 내용은 애매함…
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
When I press a button with this code on ebay.com in my webview:
html of button:
input id = "addPicturesBtn"
name = "addPicturesBtn"
type = "button"
value = "Add pictures"
class = "button"
onclick = "ebay.run(this.id,'onclick');return false;"
onkeydown = "ebay.run(this.id,'onkeydown');return false;"
title = "Add pictures"
If this button is pressed inside my webview, It sends the new window from my webview to the android browser. But if the same button is pressed from within the android browser it pops up this cool dialog type popup window (see picture)
I would like to open the popup style window on eBay like the browser does, if this button is pressed inside my webview. So that it can be closed by the user to return them to my app behind it when they are done with the popup.
Is that possible?
Here is what I have so far:
webChromeClient = new WebChromeClient() {
@Override
public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture,
Message resultMsg) {
WebView childView = new WebView(Ebay.this);
final WebSettings settings = childView.getSettings();
settings.setJavaScriptEnabled(true);
childView.setWebChromeClient(this);
childView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(childView);
resultMsg.sendToTarget();
return true;
}
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
new AlertDialog.Builder(view.getContext()).setMessage(message).setCancelable(true).show();
result.confirm();
return true;
}
Am I missing something?
Here is a picture of the android browser popup (That I'm trying to get my webview to launch from the button on ebay.com):
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Use javascript interface. Combine javascript with java and make custom dialog in java At first, enable javascript
webview.getSettings().setJavaScriptEnabled(true);
On second, you need to add javascript interface
wv.addJavascriptInterface(new DemoJavaScriptInterface(), "js");
And third, load url;
webview.loadUrl("javascript:[javascript function name here]()");
Here is some code for you, hope this can help https://github.com/scottagarman/Android-JavaScript-Interface-Example
Code credit go to the developer called "scottagarman" .
-------------------------------------------------------------------------------------------------------------------------------------------------------------
You can do it his way:
public void onCreate(Bundle savedInstanceState){
....
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new MyJSInterface(), "myappname");
webView.loadUrl("http://mysite.com/"); // or some local asset
....
}
public class MyJSInterface{
....
public void popup(){
// AlterDialog etc.
}
....
}
HTML from your website:
window.onload = function(){
window.myappname.popup();
}
I wish it would be useful for you...
By the way, be careful with 2.3 version it had a corresponding bug, just FYI))
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I am working on an app and a large part of it is having a series of useful links which open in a webview. I have the links working, but at least one of the sites requires pop up blocker to be disabled. I can not find anyway to disable pop up blocker for webview. Is there no way to do this?
-------------------------------------------------------------------------------------------------------------------------
You probably need to use the setSupportMultipleWindows in the WebSettings
Tell the WebView whether it supports multiple windows.
You can do something like this:
WebSettings settings = webview.getSettings();
settings.setSupportMultipleWindows(true);
------------------------------------------------------------------------------------------------------------------------------
That sounded like it might do the trick but I am still getting the same error. The error reads:"This warning is to let you know that your pop-up blocker has prevented the system from opening up the application. We recommend you modify your browser settings to allow pop-ups from this site to prevent this warning in the future." – James Apr 26 '12 at 18:53
------------------------------------------------------------------------------------------------------------------------------
Try also setting the javascript properties to true settings.setJavaScriptEnabled(true);settings.setJavaScriptCanOpenWindowsAutomatically(true); – Filipe Batista Apr
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I'm trying to develop a custom browser with WebView using Android API level 10 (sdk 2.3.3), unfortunately I don't know how to intercept request from the webpageto open URL in new browser window, like taps on links with target="_blank". In conformity with the API Doc I have overridden the onCreateWindow of WebChromeClient, but is not called when such a link is tapped. Could be a bug of this API level? I'm also overriding shouldOverrideUrlLoading to avoid WebView opening subsequent links in the built-in browser. Here is my sample code that opens google.com. To test it, tap "News" and then tap on any news title. The Android built-in browser normally opens it in a new browser window.
|
---------------------------------------------------------------------------------------------------------
Make sure you set supportMultipeWindows to true. Without it the onCreateWindow of the WebChromeClient will never get called.
WebSettings settings = webView.getSettings();
settings.setSupportMultipleWindows(true);
Then register a WebChromeClient and override onCreateWindow
webView.setWebChromeClient(new WebChromeClient() {
@Override public boolean onCreateWindow(WebView view, boolean dialog,
boolean userGesture, Message resultMsg)
{
WebView newWebView = new WebView(getContext());
addView(newWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
return true;
}
});
--------------------------------------------------------------------------------------------------------------
You need to take a look at this:
webView.getSettings().setSupportMultipleWindows(true);
Then onCreateWindow will get called.
-------------------------------------------------------------------------------------------------------
Could not find any solution other than injecting javascript code. I even tried to compile the built-in android browser code downloaded from google source repository but will not compile as I found out that uses some non public API. Dolphin browser also uses its own extented WebView so I had no luck finding out how they implement open new window request detection.
This javascript code gets all link tags on the loaded page and analyze if there is an attribute with target="_blank". For each of these links will add "newtab:" in front of the url value of the href attribute. Then in the shouldOverrideUrlLoading() method I check if url begins with "newtab:" string, in which case I open a new tab.
Here are the code snipets:
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript: var allLinks =
document.getElementsByTagName('a');
if (allLinks) {var i;for (i=0; i<allLinks.length; i++)
{var link = allLinks[i];var target = link.getAttribute('target');
if (target && target == '_blank') {link.setAttribute('target','_self');
link.href = 'newtab:'+link.href;}}}");
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String urls) {
if (urls.startsWith("newtab:")) {
addTab(); //add a new tab or window
//strip "newtab:" and load url in the webview of the newly created tab or window
loadNewURL(urls.substring(7));
} else {
view.loadUrl(urls); //load url in current WebView
}
return true;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I am trying to implement facebook like functionality using android webview. It is working fine without "confirm" dialog. But its not working when like needs confirmation. Here is the code snippet i am using.
private void setUpWebView() {
likeWebView.setVerticalScrollBarEnabled(false);
likeWebView.setHorizontalScrollBarEnabled(false);
likeWebView.setWebViewClient(new FacebookWebViewClient());
likeWebView.setWebChromeClient(new MyChromeClient());
likeWebView.getSettings().setJavaScriptEnabled(true);
String url = getFacebookLikeUrl();
likeWebView.loadUrl(url);
}
I am also setting ViewClient and WebChromeClient.
private String getFacebookLikeUrl() {
return "http://www.facebook.com/plugins/like.php?" + "href="
+ URLEncoder.encode(mUrl) + "&access_token="
+ URLEncoder.encode(facebook.getAccessToken());
}
Please help me out to solve this issue. Thanks in advance.
android facebook-like facebook-android-sdk
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I have solved this issue by over ridding onCreateWindow() method of WebChromeClient and enabling these two options for webview. likeWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); likeWebView.getSettings().setSupportMultipleWindows(true); Thanks to all. – Shweta Oct 10 '11 at 10:19 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Facebook like confirmation opens confirm_widget in new window. So your webview should support Multiple Window opening. for this setJavaScriptCanOpenWindowsAutomatically(true) and setSupportMultipleWindows(true) for your webview-
private void setUpWebView() {
likeWebView = new WebView(getContext());
likeWebView.setWebViewClient(new FacebookWebViewClient());
likeWebView.setWebChromeClient(new MyChromeClient());
final WebSettings webSettings = likeWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setSupportMultipleWindows(true);
String url = getFacebookLikeUrl();
likeWebView.loadUrl(url);
likeWebView.setLayoutParams(FILL);
mContent.addView(likeWebView);
}
Facebook like confirmation calls onCreateWindow() method. SO override the onCreateWindow method in WebChromeClient -
final class MyChromeClient extends WebChromeClient {
// Add new webview in same window
@Override
public boolean onCreateWindow(WebView view, boolean dialog,
boolean userGesture, Message resultMsg) {
WebView childView = new WebView(getContext());
childView.getSettings().setJavaScriptEnabled(true);
childView.setWebChromeClient(this);
childView.setWebViewClient(new FacebookWebViewClient());
childView.setLayoutParams(FILL);
mContent.addView(childView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(childView);
resultMsg.sendToTarget();
return true;
}
// remove new added webview whenever onCloseWindow gets called for new webview.
@Override
public void onCloseWindow(WebView window) {
mContent.removeViewAt(mContent.getChildCount() - 1);
}
}
confirm_widget for like calls onCloseWindow when user click either Like or Cancel. On this method remove last added webview.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I used this for Stripe Checkout which opens a new window in mobile devices for payments.
Based on @Shweta's response :
In your activity:
package myapp.app;
/*** imports ***/
public class LoggedActivity extends FragmentActivity
{
public WebView myWebView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.logged);
// retrieve the main container
LinearLayout container = (LinearLayout) findViewById(R.id.logged_webviews_container);
// layout params applied to the webviews in order to fit 100% the parent container
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
myWebView = new WebView(this);
myWebView.setLayoutParams(layoutParams);
myWebView.setWebViewClient(new BetterWebViewClient(this));
WebSettings settings = myWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setSupportMultipleWindows(true);
// on this instruction, we set our extended class below as the Parent Webview webchromeclient
myWebView.setWebChromeClient(new PopupWebView(this, myWebView, container, layoutParams));
// load URL
myWebView.loadUrl('http://www.mywebsite.com');
container.addView(myWebView);
}
}
Add this class which extends WebChromeClient
package myapp.app;
/*** imports ***/
public class PopupWebChromeClient extends WebChromeClient {
protected Activity activity;
protected WebView parentWebView;
protected RelativeLayout container;
protected WebView popupView;
PopupWebChromeClient(
Activity activity,
WebView parentWebView,
RelativeLayout container
)
{
super();
this.activity = activity;
this.parentWebView = parentWebView;
this.container = container;
}
@Override
public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture,
Message resultMsg) {
this.parentWebView.setVisibility(WebView.GONE);
this.popupView = new WebView(this.activity);
// setup popuview and add
this.popupView.getSettings().setJavaScriptEnabled(true);
this.popupView.setWebChromeClient(this);
this.popupView.setWebViewClient(new ApkfWebViewClient(this.activity, true));
this.popupView.setLayoutParams(new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT
));
this.container.addView(this.popupView);
// send popup window infos back to main (cross-document messaging)
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(popupView);
resultMsg.sendToTarget();
return true;
}
// remove new added webview on close
@Override
public void onCloseWindow(WebView window) {
this.popupView.setVisibility(WebView.GONE);
this.parentWebView.setVisibility(WebView.VISIBLE);
}
}
In your layout xml, don't set webviews since we create them on the fly.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
출처: http://ymson.tistory.com/entry/WebView-windowopen-%EC%B2%98%EB%A6%AC
iOS 와 마찬가지로 Android 에서도 휴대폰 인증, 우편번호 찾기 등에서 window.open 이 되지 않는 문제가 발생.
WKWebView 에서 한것 처럼 window 처리를 위한 method 들(WebChromeClient)을 구현 하여서 해결.
iOS는 없는 Window Close 에 대한 메소드도 있다.
관리하기가 훨씬 더 쉬움.
// 웹뷰 세팅// 팝업(window.open) 허용. setJavaScriptCanOpenWindowsAutomatically만
//설정하는 경우 Main WebView에 Url 이 로딩되므로 setSupportMultipleWindows 설정 후
//onCreateWindow를 Override 해야 함.webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setSupportMultipleWindows(true);
// 메소드 구현
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
WebView newWebView = new WebView(view.getContext());
configurateWebView(newWebView);
.... 웹뷰 구성
mWebViewContainer.addView(newWebView); // 화면에 보여질 수 있도록 add view
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
return true;
}
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
mWebViewContainer.removeView(window); // 화면에서 제거
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
출처: http://www.androidpub.com/1618331
질문란에 여러개가 올라와서 이곳에 글을 올립니다.
Popup 부분은 구글 기본 브라우저 소스를 참조하면 작업이 좀 들어가긴 하지만 어렵지 않게 구현가능합니다.
간략한 설명은
1. http://android.git.kernel.org/ 에서 platform/packages/apps/Browser.git 다운로드
2. WebView.getSettings().setSupportMultipleWindows(true); 설정
3. webViewClient, webChromeClient 지정
4. tab.java - webChromeClient 의 onCreateWindow() 참조
setSupportMultipleWindows(true) 에 의해 onCreateWindow() 가 호출됩니다.
이때, onCreateWindow() 내에 popup창으로 사용할 view생성해서 webkit에 던져주면 표시됩니다.
-----------------------------------------------------------------------------------------------------------------
감사합니다~ 정말 많은 도움 되었습니다~ 일단 구조는 어느정도 이해가 되는데, 제대로 구현하기가 힘드네요 ㅇ_ㅇ;;
tab.java 파일 열심히 들여다보는중입니다만...ㅇ_ㅇ;; oncreate 이용해서 새 브라우저는 어떻게 띄웠는데,
기본 브라우저처럼 close 스크립트가 먹질않고;;데이터도 안넘어가네요 ㅠ;
괜찮으시다면 조금더 힌트를 주시면 감사하겠습니다..~;;;
2011.06.24 22:38:42
초맨
close 는 onCloseWindow() 에 간단히 구현되어었습니다.
2011.06.27 18:38:52
찬영이아빠
아래와 같이 코딩을 했는데 window.open script를 의해서 webview에서 주소창이 보이는 새창이 뜨네요.
처음에 webview가 뜬 페이지에서 web처럼 창만 뜰수가 없나요? 그리고 모달팝업은 작동이 되지 않네요(window.showModalDialog ...)
@Override
public boolean onCreateWindow(WebView view, boolean dialog,
boolean userGesture, Message resultMsg) {
WebView childView = new WebView(Intro.this);
final WebSettings settings = childView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setSupportMultipleWindows(true);
childView.setWebChromeClient(this);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(childView);
resultMsg.sendToTarget();
2011.07.29 20:10:26
SGLEE
감사합니다~ 크롬클라이언트 추가하는것만으로 안뜨던 팝업들이 뜨네요~
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'스마트기기개발관련' 카테고리의 다른 글
모바일 푸시알람 개발 ios android .. 등등 푸시개발 관련 (0) | 2020.09.20 |
---|---|
안드로이드 앱 바로가기 만들기, 웹주소를 모바일에 홈화면에 아이콘 바로가기 만들기 관련 (0) | 2020.09.20 |
스마트앱개발 [KISA] 한국인터넷진흥원 스마트폰 앱 위반내역 송부 및 개선 요청 관련(개인정보 암호화 송수신 전송 위반(안정성 확보 조치 위반), 접근권한 (권한별 이유 고지 위반) 등등) (0) | 2020.09.20 |
안드로이드 IOS 등등 스마트폰 해상도 관련 (0) | 2020.09.19 |
애플 IPA 파일 아이폰 아이패드에 설치하기 관련 (1) | 2019.11.19 |