Problem resolved, I forgot to add this line:
myWebView.getSettings().setJavaScriptEnabled(true);
I havew a WebView with a email link.
Here is my HTML email link:
href="javascript:location.href='mailto:'+String.fromCharCode(97,110,105,109,97,108,115,64,109,100,112,105,46,99,111,109)+'?'">animals#mdpi.com</a>.</p>
I am trying to catch when the user clicks on this link with this code:
myWebView.setWebViewClient(new WebViewClient()
{
#Override
public boolean shouldOverrideUrlLoading(WebView wv, String url) {
if(url.contains("mailto")){
System.out.println("mailto");
}
return true;
}
});
But I am never entering in the if.
Here is the solution
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient()
{
#Override
public boolean shouldOverrideUrlLoading(WebView wv, String url) {
if(url.contains("mailto")){
System.out.println("mailto");
}
return true;
}
});
Related
I have a webview app and facing a problem that
when I click on Hyperlink then it opens in default browser.
But I want to open that link in same webview.
How to open it in same webview.
Here is my code.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.myWebView);
myWebView.loadUrl("file:///android_asset/abc/index.html");
myWebView.setWebViewClient(new MyWebViewClient());
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
}
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("file:///android_asset/abc/index.html")) {
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
Do it like,
myWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
Return false in all cases.
ok.. you have added a WebViewClient also..
then try it in this way...
myWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
this should work for you..
How can I click on a link that is provided in the WebView data that I load?
The WebView data that is load is in HTML format as:
<P CLASS="western" ALIGN=JUSTIFY STYLE="margin-bottom: 0.14in">Further
here</P>
The WebView is placed inside a scroll view and its webClient is as:
webViewClient = new WebViewClient()
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
#Override
public void onLoadResource(WebView view, String url)
{
}
};
webView = (WebView) findViewById(R.id.tos); // Defining the WebView for the terms and conditions and loading the required data
webView.setWebViewClient(webViewClient);
webView.loadData(getResources().getString(R.string.terms_of_service), "text/html", "UTF-8");
The problem is that when I click on the Link no action takes place. How can this be resolved?
use this code to open
WebView webView;//make sure to initialize
webView.setWebViewClient(webViewClient);
WebViewClient webViewClient= new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
return true;
}
#Override
public void onLoadResource(WebView view, String url){
if( url.equals("http://yoururl.com") ){
// do something
}
}
}
I Want to open a WeView inside my App. It works fine for few pages navigation, then suddenly it shows "Resource not found". Here is my code. Am I missing something here.
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://xyz.example.com");
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
Return false instead of true in shouldOverrideUrlLoading()
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://xyz.example.com");
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
I have a WebView on my application and some links which are URL adresses.
Some of them don't have the baseURL, only something like "/abc/abc"
I would like to set the baseURL for all the links starting with "/".
I have tryed this:
WebView wv = (WebView) findViewById(R.id.EditorialWebView);
wv.setBackgroundColor(0x00000000);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadDataWithBaseURL("", editorialBoard, "text/html", "utf-8", "");
wv.setWebViewClient(new WebViewClient()
{
#Override
public boolean shouldOverrideUrlLoading(WebView wv, String url) {
if (url.startsWith("/"))
{
wv.loadUrl("http://www.mdpi.com"+url);
}
return true;
}
});
But nothing happens.
Try something like this
myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.startsWith("/")) {
Uri u = Uri.fromParts("http://www.domain.com", url, "");
view.loadUrl(u);
}
return true;
}
});
Please let me know if it works for you as I am unable to test it at the moment.
My application current view is In web view..inside which if user clicks on a pdf link.it should get installed on sd card and then available options for viewing must be shown ..if no Viewer available then a message should be shown
protected void onStart()
{
super.onStart();
myWebView.loadUrl("URl");
myWebView.setWebViewClient(
new WebViewClient()
{
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.endsWith("pdf"))
{
// do eet return true; } return false;
} });
myWebView.getSettings().setJavaScriptEnabled(true);
/*WebSettings webSettings = myWebView.getSettings(); \
webSettings.setBuiltInZoomControls(true); webSettings.setSupportZoom(true);*/
}
Overide the function shouldOverrideUrlLoading()
youWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.endsWith("pdf")) {
// do eet
return true;
}
return false;
}
});