Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Webbrowser control - opening link in new window

Webbrowser control - opening link in new window

Scheduled Pinned Locked Moved C#
help
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Oohmesh
    wrote on last edited by
    #1

    Hi Coders I am using a webbrowser control in my winform application. I want to open all the links in the same window even though if the link is having the target=_blank property also. Its very urget. Please help me out. Oohmesh

    A 1 Reply Last reply
    0
    • O Oohmesh

      Hi Coders I am using a webbrowser control in my winform application. I want to open all the links in the same window even though if the link is having the target=_blank property also. Its very urget. Please help me out. Oohmesh

      A Offline
      A Offline
      Anh_Tuan
      wrote on last edited by
      #2

      You need to add event handlers to handle "NewWindow" event when the user clicks on a link with the target not on the current webbrowser 1. For Pre Windows XP SP2 axWebBrowser.NewWindow2 2. For Windows XP2 and later there is another event named axWebBrowser.NewWindow3 The whole code for this would look axWebBrowser.NewWindow2 += new AxSHDocVw.DWebBrowserEvents2_NewWindow2EventHandler(axWebBrowser_NewWindow2); try { axWebBrowser.NewWindow3 += new AxSHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(axWebBrowser_NewWindow3); } catch ( Exception ) { // Not XP SP2 - just ignore } Now in the event handlers all you have to do is block the new window from opening by putting e.Cancel = true; and redirect the current webbrowser to the new URL sent by the event. See more at NewWindow3[^] Jup

      J 1 Reply Last reply
      0
      • A Anh_Tuan

        You need to add event handlers to handle "NewWindow" event when the user clicks on a link with the target not on the current webbrowser 1. For Pre Windows XP SP2 axWebBrowser.NewWindow2 2. For Windows XP2 and later there is another event named axWebBrowser.NewWindow3 The whole code for this would look axWebBrowser.NewWindow2 += new AxSHDocVw.DWebBrowserEvents2_NewWindow2EventHandler(axWebBrowser_NewWindow2); try { axWebBrowser.NewWindow3 += new AxSHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(axWebBrowser_NewWindow3); } catch ( Exception ) { // Not XP SP2 - just ignore } Now in the event handlers all you have to do is block the new window from opening by putting e.Cancel = true; and redirect the current webbrowser to the new URL sent by the event. See more at NewWindow3[^] Jup

        J Offline
        J Offline
        Jax_qqq
        wrote on last edited by
        #3

        Where i ll find this "axWebBrowser" class...Pls send the namespace. Aur it's an coponent u r using...:) Anuj

        A 1 Reply Last reply
        0
        • J Jax_qqq

          Where i ll find this "axWebBrowser" class...Pls send the namespace. Aur it's an coponent u r using...:) Anuj

          A Offline
          A Offline
          Anh_Tuan
          wrote on last edited by
          #4

          That's the variable name. The activeX browser could be found on your system. With .NET 1.1 the simplest way is that you should import that COM component from system32/shdocvw.dll. .NET 2.0 already have a web browser control for you by default from the toolbox. -Good Luck Jup

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups