# SRC\_IMAGE\_ANCHOR\_TYPE not fetching the inner link on WebView

**URL:** <https://discuss.kotlinlang.org/t/src-image-anchor-type-not-fetching-the-inner-link-on-webview/30160>\
**Category:** Android\
**Created:** [March 26, 2025, 4:34pm UTC](https://discuss.kotlinlang.org/t/src-image-anchor-type-not-fetching-the-inner-link-on-webview/30160 "2025-03-26T16:34:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ferreira.kevin94](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ferreira.kevin94/32/11154_2.png) [@ferreira.kevin94](https://discuss.kotlinlang.org/u/ferreira.kevin94)\
**Post date:** [March 26, 2025, 4:34pm UTC](https://discuss.kotlinlang.org/t/src-image-anchor-type-not-fetching-the-inner-link-on-webview/30160/1 "2025-03-26T16:34:30Z")

</div>

While using “hitTestResult” on WebView, i actually face an issue while fetching the inner link of an “image link”, in which it seems to be worked with “SRC\_IMAGE\_ANCHOR\_TYPE” but the result of this attempt results into fetching the image link instead of the inner website link, the program im building is a menu that pops up when long pressed over any type of link and the issue itself is about only “image links” AKA when you use SRC\_IMAGE\_ANCHOR\_TYPE… How to solve this? thanks

```auto
    val hitTestResult = (v as WebView).hitTestResult
                when (hitTestResult.type) {
                    WebView.HitTestResult.SRC_ANCHOR_TYPE -> {
                        hitTestResult.extra?.let { showLinkMenu(it) }
                        true
                    }
                    WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE -> {

                        hitTestResult.extra?.let { showLinkMenu(it) }
                        true
                    }
                    WebView.HitTestResult.IMAGE_TYPE -> {
                        hitTestResult.extra?.let { showLinkMenu(it) }
                        true
                    }
                    else -> false
                }
            }

private fun showLinkMenu(url: String) {

        val menuView = layoutInflater.inflate(R.layout.menu_link_options, null)

        val popupWindow = PopupWindow(
            menuView,
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT,
            true
        )
        popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(this, R.drawable.menu_background))

        val linkUrlText = menuView.findViewById<TextView>(R.id.linkUrlText)
        linkUrlText.text = url

        menuView.findViewById<TextView>(R.id.openInNewTab).setOnClickListener {
            addNewTab(url) // Open the link in a new tab
            popupWindow.dismiss()
        }

    
        popupWindow.showAtLocation(webView, Gravity.CENTER, 0, 0)
    }

```
