获取网页浏览中点击图片的链接

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取网页浏览中点击图片的链接相关的知识,希望对你有一定的参考价值。

我想获取在Webview中单击的图像的链接,以便在新的意图中显示它。我想要图像的网站在点击时不会全屏打开图像。我想要类似下面的代码,但网站不会在同一个选项卡中打开图像。

参考代码:

public class MyWebViewClient extends WebViewClient {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url == null){
  return false;
}else if (url.trim().toLowerCase().endsWith(".img")) {//use whatever image formats you are looking for here.
  String imageUrl = url;//here is your image url, do what you want with it
}else{
  view.loadUrl(url);
}
 }
}
答案
public class MyWebViewClient extends WebViewClient {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url == null){
return false;
}else if (url.trim().toLowerCase().endsWith(".img")) {//use whatever 
image formats you are looking for here.
 String imageUrl = url;//here is your image url, do what you want with 
 it
 Intent intent = new Intent(this, NewActivity.class);
//pass from here the data to next activity and load there
intent.putExtra("yourURL", imageUrl);

startActivity(intent)

}else{
view.loadUrl(url);
 }
}
}

以上是关于获取网页浏览中点击图片的链接的主要内容,如果未能解决你的问题,请参考以下文章

微信小程序代码片段

HTML代码片段

HTML代码片段

在HTML静态网页中记录图片被点击的次数统计代码?

使用selenium的方式获取网页中图片的链接和网页的链接,来判断是否是死链

Python练习册 第 0013 题: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-),(http://tieba.baidu.com/p/2166231880)(代码片段