Windows Develop Bookmark and Share   
 index > Windows Forms General > WebBrowser Control - How to suppress opening of new windows?
 

WebBrowser Control - How to suppress opening of new windows?

Hi,

I am working on kiosk-browser application. I would like to suppress opening of all new windows and force the webbrowser to open them in it. So I observe NewWindow event and cancel new window opening and then navigate to Url of the new window:

private void webBrowser_NewWindow(object sender, CancelEventArgs e)
{
      e.Cancel = true;
      webBrowser.Url = new Uri(webBrowser.StatusText);            
}

It works fine on many websites, HTML pages are correctly opened in webbrowser, PDF files are openen in webbrowser also (in acrobat reader plugin).

But - I have found one website where HTML anchors to PDF files are made like this (nothing unusual):
<a target="_blank" href="http://test.com/file.pdf">PDF file</a>

And for this link:
- NewWindow event is normally fired (no new browser-window is opened)
- browser pops-up windows that shows like file.pdf is being downloaded (to temp folder) and then this file.pdf is opened with Adobe Reader application (so not in browser).

If I make my testing html page and copy their anchor then everything works fine - file.pdf is opened in browser.

My question is: How to make all files open in webBrowser?

Thanks a lot
Mirek Vanicky


Miroslav Vanicky  Tuesday, September 08, 2009 10:47 AM

Hi,

I test on my side, write the following between body tag.

<a target="_blank" href="http://####.pdf">

PDF file

</a>

When I click “pdf file� webbroswer opens the pdf file inside.

I guess downloading and opening with Adobe Reader application actions cause by other setting.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Tuesday, September 15, 2009 7:45 AM
As I have written - for almost all URL's it behaves as you wrote, it opens pdf file inside WebBrowser component.

But try this URL: Test URLinWebBrowser component the way I described.
Does it open in WebBrowser?


Miroslav Vanicky  Wednesday, September 16, 2009 6:53 AM

You can use google to search for other answers

Custom Search

More Threads

• Connection failing from workstation
• where can I find Microsoft.Office Namespace?
• Could not find any resources appropriate for the specified culture or the neutral culture. Images on a form
• Progress Bar Pro Questions
• How to get ListViewItem and save them to a text file?
• form is getting minimized ????????
• Shortcut keys and a RichTextBox
• Activate an application
• unhandled exception
• Events form COM Object