Suppress links in WebView

avslnavsln USMember

I have a web page that I would like to display in a Web View in my app. But the page has links. Is there any way I can suppress all links on a page when it is being displayed in a WebView

Answers

  • N_BauaN_Baua INMember ✭✭✭✭✭

    Hi @avsln,

    The best way for you to write a parser and replace hyperlinks with #/remove the <a> retaining the link-text.
    Or Else

    For Android:

    For iOS:
    I guess UIWebView has some delegates to be override

    Hope it helps.

    -- N Baua

  • JohnHardmanJohnHardman GBUniversity ✭✭✭✭✭
    edited September 23

    @avsin - Your Xamarin.Forms app can inject and execute a small piece of JavaScript once the page is loaded into the WebView. That JavaScript can quickly replace any links found in the HTML of the page.

    Alternatively, I did see a forum post in the last few days about how to retrieve the HTML of a downloaded page back into your C#. Using that would allow you to use C# to replace any links, before putting the HTML back into the WebView.

    If you've not done JavaScript before, I highly recommend the book "DOM Scripting: Web Design With Javascript and the Document Object Model" by Jeremy Keith - it explains exactly how to do this sort of thing, and is one of the most readable tech books I've ever read.

Sign In or Register to comment.