locked
Prevent redirect page using javascript on webview RRS feed

  • Question

  • User375036 posted

    Does xamarin form webview support to cancel redirecting page from webpage by using javascript ? I've tried to cancel redirecting page by e.cancel = true, but it doesn't work. In my case i use xamarin form 3.6 latest. Here's my code

        e.Cancel = true;
    
                try
                {
                    var vmPayment = new VMPayment();
    
                    if (currentUrl.Contains("paymentId"))
                    {
                        vmPayment.PaymentId = currentUrl.Split('=').ToList().Last();
                    }
                    else if (currentUrl.Contains("transaction_id"))
                    {
                        vmPayment.PaymentId = currentUrl.Split('=').ToList().Last();
                    }
    
                    PaymentResponse(vmPayment);
                }
                catch (Exception exception)
                {
    
                }
    
    Friday, November 1, 2019 5:25 AM

All replies

  • User369978 posted

    Where you place the above code ? I place in Navigating event and it works .

    void webOnNavigating(object sender, WebNavigatingEventArgs e)
    {
         if (e.Url.StartsWith("xxx"))
         {
             e.Cancel = true;
         }
    }
    

    Check my previous answer : https://stackoverflow.com/a/49065912/8187800.

    Friday, November 1, 2019 8:15 AM
  • User375036 posted

    I put the code inside navigating event handler. But it doesn't work.

    Friday, November 1, 2019 1:42 PM
  • User369978 posted

    What do you mean by it doesn't work ?

    Navigating event not triggered or e.Cancel = true; not work ?

    Monday, November 4, 2019 8:05 AM
  • User375036 posted

    e.Cancel = true; doesn't work.

    Tuesday, November 5, 2019 1:14 AM
  • User369978 posted

    It is pretty weird , it works on my side , could you provide us a basic sample to test ?

    Tuesday, November 5, 2019 12:29 PM