T
T
TechNOIR2018-02-06 23:10:01
C++ / C#
TechNOIR, 2018-02-06 23:10:01

C#. webbrowser. How to limit the list of URLs that can be navigated inside WebBrowser elements?

Good afternoon.
Can you please tell me how to limit the list of URLs that can be navigated inside WebBrowser elements?
For example WebBrowser will only load site.com. It has links to other sites, for example site2.com.
It is necessary to somehow prohibit opening so that you can only follow links containing site.com.
Is this possible? Thanks in advance!!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FreeBa, 2018-02-07
@FreeBa

I think the idea is clear.

var whiteList = new string[] { "..." };

webBrowser1.Navigate("https://google.com");
webBrowser1.Navigating += (s, arg) =>
{
       if (!whiteList.Any(x => x == arg.Url.ToString())) arg.Cancel = true;
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question