0

I made some LinkLabels on my Form, they are the link for each chapter of a eBook. According to that, I wanted to navigate on my WebBrowser using that labels but the browser isn't navigating not even for a legit Uri like "www.google.com".

If I click on the links displayed on my document from the browser, it will go to the right section, otherwise it will not move...

I have tried this link How can I navigate a webbrowser programmatically? but I didnt worked for me.

So, this is my code:

private void createBrowser()
{
  wb = new WebBrowser();
  wb.ScrollBarsEnabled = true;
  showText.Controls.Add(wb);
  wb.SetBounds(0, 0, showText.Width, showText.Height);
  wb.DocumentText = epub.GetContentAsHtml();

}       

private void linkedlabel_click(object sender, LinkLabelLinkClickedEventArgs e) {
  // none of this worked...
  // wb.Navigate(e.Link.LinkData.ToString());
  // wb.Document.All[e.Link.LinkData.ToString()].InvokeMember("click");
}

I tried to add some navigating listeners but nothing... My e.Link.LinkData.toString() returns the the pages, like "0001.html", "0002.html", etc.

Community
  • 1
  • 1
João Silva
  • 531
  • 4
  • 21
  • 40
  • 1
    I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Jan 12 '15 at 04:48

1 Answers1

1

After create the WebBrowser with Visual Studio, check if your URL is correct. I mean, If the page 0001.html is in your desktop ensure to use the complete direction. Example:

    private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        //If your website is on the startup path
        webBrowser1.Navigate(Application.StartupPath + "\\0001.html");
        //OR
        //If your website is on the internet
        webBrowser1.Navigate("http://www.website.com/0001.html");
    }
Mariachi
  • 139
  • 4
  • Well, the page is a chapter of a eBook, I load all "pages" as html to a document and I wanted to navigate through them, the html have hyperlinks inside them, and I can navigate through them, but since I want to dispay a index with all chapters, my problem is make the web browser navigate to them – João Silva Jan 12 '15 at 04:11
  • @JoãoSilva to navigate/link within a page you will need to use `#[a tag id]` links. E.g. the answer this comment is linked to is (http://stackoverflow.com/questions/27894719/how-to-programmatically-navigate-on-webbrowser-c-sharp/27895073#27895073) – Taras Alenin Jan 12 '15 at 04:18
  • Well, I guess it is some bug... I tried to navigate to "#loft_html" that is one of my pages. I made every lable go there, but the browser just doesn't move, I checked and the url changes, the browser just doesn't reload – João Silva Jan 12 '15 at 04:25