locked
Add Link in webbrowser control using VB NET RRS feed

  • Question

  • How to insert a link in webbrowser control without webBrowser1.Document.ExecCommand("CreateLink", True, Nothing).

    I've tried to add with webBrowser1.Document.ExecCommand("CreateLink", False, "<a href='http://www.microsoft.com'>microsoft</a>"), but doesn't work.

    Note: I don't have problem with:

    webBrowser1.Document.ExecCommand("insertimage", True, Nothing)

    webBrowser1.Document.ExecCommand("CreateLink", True, Nothing)

    webBrowser1.Document.ExecCommand("EditMode", True, Nothing)

    and others command

    could you help me?

     


    memo

    Wednesday, April 13, 2011 2:09 PM

Answers

  • Hi gcontreras,

    What do you mean "it doesn't work"? Any error message or ? It works all right on my side (Windows 7+ VS2010) with following code:

     webBrowser1.Document.ExecCommand("CreateLink",true,"<a href='http://www.microsoft.com'>microsoft</a>");

    Note that you need to fill the webBrowser with some content (eg. by set Url property) at first, otherwise it will throw NullReferenceException.


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Helen Zhou Wednesday, April 27, 2011 9:44 AM
    • Marked as answer by Helen Zhou Wednesday, April 27, 2011 9:45 AM
    Wednesday, April 20, 2011 7:27 AM

All replies


  • Have you tried manipulating directly the html with the WebBrowser1.DocumentText property?  I believe that is what I have done in the past.

    --
    Mike
    Wednesday, April 13, 2011 10:01 PM
  • Hi,
    If I am understanding your requirement properly and if you just need a link in WebBrowser control, you can do so by placing a LinkLabel control over the WebBrowser control.

    Then, you can write your code as desired on the click event of the link.
    I tried the same to get results as in the image here.

    https://sites.google.com/site/konnichiwaall/Home/WB0.JPG?attredirects=0(Form
    https://sites.google.com/site/konnichiwaall/Home/WB1.JPG?attredirects=0(WebBrowser control used with a link on top left corner.)
    https://sites.google.com/site/konnichiwaall/Home/WB2.JPG?attredirects=0 with WebBrowser control and link)
    (New Page opened on click on the link. Link still stays there.)

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Dim newURI As New Uri("http://social.msdn.microsoft.com/Forums/en-US/user/forumsthreads?page=2")
        WebBrowser1.Url = newURI
    End Sub
    

    Regards, Lakra :) - If the post is helpful or answers your question, please mark it as such.
    Thursday, April 14, 2011 2:30 AM
  • Hello gcontreras,

    Can you be more specific with your question?

    To add a link in webBrowser control, you can get some useful information on the following links:

    Please let me know if they didn't help and elaborate more about the question.

    Best wishes,

     

     


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, April 15, 2011 2:56 AM
  • Hi gcontreras,

    What do you mean "it doesn't work"? Any error message or ? It works all right on my side (Windows 7+ VS2010) with following code:

     webBrowser1.Document.ExecCommand("CreateLink",true,"<a href='http://www.microsoft.com'>microsoft</a>");

    Note that you need to fill the webBrowser with some content (eg. by set Url property) at first, otherwise it will throw NullReferenceException.


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Helen Zhou Wednesday, April 27, 2011 9:44 AM
    • Marked as answer by Helen Zhou Wednesday, April 27, 2011 9:45 AM
    Wednesday, April 20, 2011 7:27 AM
  • Hi G,

    It is not important if the program language is VB or C#

    You navigate to a link by using the navigate property

    webBrowser1.Navigate("www.Microsoft.Com") in C# with a semicolon at the end. 

     

     


    Success
    Cor
    Wednesday, April 20, 2011 7:37 AM
  • Hi gcontreras,

    If you feel the solution I gave doesn’t real answer your question, please feel free to unmark it and update the thread.

    Regards,


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 27, 2011 9:46 AM
  • The answer given by Microsoft team  Helen Zhou [MSFT] is wrong

    Actually Question is How to insert a link <a href = "www.abobjects.com">click here </a>

    This can be done as below

      Clipboard.SetText(str);
            editor.Copy();
          editor.Paste();

     

    by  Parvez Ahmad Hakim, www.abobjects.com

    Saturday, May 7, 2011 6:23 PM