Search code examples
c#.netcompact-frameworkbrowserpocketpc

How to disable mailto popup in WebBrowser for Pocket PC .NET CF 3.5?


For security reasons, I'm trying to disable the opening of Outlook (or any default mail client) when the user clicks a popup in my subclassed WebBrowser viewing a local html file. I've tried replacing the DocumentText with a version sans the "mailto:" link references, but this has continuously failed (no matter what I try, it keeps sticking to the about:blank page after setting the DocumentText).

The best solution to my problem would be to completely disable any default mail clients, via the registry or other means, but I am open to anything I haven't tried yet. Any ideas?


Solution

  • I was able to fix my security issue by overwriting the html file to contain no "mailto" references. After the file is replaced, I simply refreshed it:

      TextReader tr = File.OpenText(e.Url.LocalPath);
      htmlFile = tr.ReadToEnd();
      tr.Close();
      tr.Dispose();
    
      if (htmlFile.Contains("mailto:[email protected]"))
      {
          htmlFile = htmlFile.Replace("mailto:[email protected]", @"about:blank");
    
          //Recreate new file with fixed html
          File.Delete(e.Url.LocalPath);
          TextWriter tw = File.CreateText(e.Url.LocalPath);
          tw.Write(htmlFile);
          tw.Flush();
          tw.Close();
          tw.Dispose();
    
          Refresh();
      }