Propagate link events to jxbrowser

I want to catch and destroy (disallow redirection) event links to teamdev jxbrowser . Suppose the content

<a href="testlink">link</a>

      

When a user clicks on a link, I want to be informed that the user has clicked on the link and received the URL, but I do not allow the page to be changed (the link must be used).

The problem is that the quoted links of the anchored tag don't start with any protocol ( http: // or https: // and don't end with any .html or so on). For example, a link looks like this:

<a href="foo">link<a>

and we want when the user clicks on the link, we get information that the clicked string foo . I know the links in this tag are invalid and not well formed due to standards, but the content is generated using some specific business process rules and then set in JxBrowser. And we cannot change the way we create links.

In the example below, we get: blank for the url, which is not necessary information. If we go to

<a href="http://foo">link</a> 

      

then it works fine, but we cannot change the links (content) as I mentioned earlier.

browser.addLoadListener(new LoadListener () {
    public void onStartLoadingFrame(StartLoadingEvent arg0) {
         System.out.println("link click occured " + arg0.getValidatedURL());
         arg0.getBrowser().stop();

    }
); 

      

+3


source to share


1 answer


LoadHandler allows you to handle any load related actions. Using LoadHandler, you can determine the type of load and cancel any load events. Here's an example:



browser.setLoadHandler(new DefaultLoadHandler() {
    @Override
    public boolean onLoad(LoadParams params) {
        if (params.getType() == LoadType.LinkClicked) {
            System.out.println("Link clicked: " + params.getURL());
            return true;
        }
        return false;
    }
});

      

+1


source







All Articles