How to get loaded URL?

Having problems with building or using the JCEF Java binding? Ask your questions here.

How to get loaded URL?

Postby Andy » Wed Feb 04, 2015 2:25 pm

Hi I am new to CEF, I have build the JCEF based browser by following some tutorials. I want to know where the loaded/displayed website's URL is stored?

E.g: Suppose I visit google[dot]com and search for CEF, then some search results get displayed. Now I click the first search result, so where is the URL of this clicked search result is stored? Is there any method or function to get the URL of clicked links?

- Thanks
Andy
Newbie
 
Posts: 3
Joined: Wed Feb 04, 2015 2:14 pm

Re: How to get loaded URL?

Postby magreenblatt » Wed Feb 04, 2015 3:09 pm

CefRequestHandler::OnBeforeBrowse will be called followed by CefRequestHandler::OnBeforeResourceLoad. You can get the URL from the CefRequest passed to these methods. After the page has loaded you can get the URL from the CefBrowser instance.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to get loaded URL?

Postby Andy » Mon Feb 09, 2015 12:58 am

I m still confused! a code snippet would help me! How do I check if the page is loaded or not.
Andy
Newbie
 
Posts: 3
Joined: Wed Feb 04, 2015 2:14 pm

Re: How to get loaded URL?

Postby magreenblatt » Mon Feb 09, 2015 3:35 pm

Here's an example based on the code in tests/detailed/MainFrame.java:
Code: Select all
    client_.addLoadHandler(new CefLoadHandlerAdapter() {
      @Override
      public void onLoadingStateChange(CefBrowser browser,
                                       boolean isLoading,
                                       boolean canGoBack,
                                       boolean canGoForward) {
        if (!isLoading) {
          // The page has finished loading.
          String url = browser.getURL();
          // Do something with |url|
        }
      }
    }
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to get loaded URL?

Postby Andy » Tue Feb 10, 2015 6:33 am

Thank You very much! :) You Rock !!! :D
Andy
Newbie
 
Posts: 3
Joined: Wed Feb 04, 2015 2:14 pm


Return to JCEF Forum

Who is online

Users browsing this forum: Google [Bot] and 23 guests