c# - Suppress WebBrowser mailto -
i have webbrowser control in form.
i want when user click on link (href mailto) register website button clicked, not open new window (neither outlook nor other website).
i have found code, doesn't work:
private void webbrowser1_documentcompleted(object sender, webbrowserdocumentcompletedeventargs e) { textreader tr = file.opentext(webbrowser1.url.tostring()); string htmlfile = tr.readtoend(); tr.close(); tr.dispose(); if (htmlfile.contains("mailto:")) { htmlfile = htmlfile.replace("mailto:", @"mail"); //recreate new file fixed html file.delete(e.url.localpath); textwriter tw = file.createtext(e.url.localpath); tw.write(htmlfile); tw.flush(); tw.close(); tw.dispose(); refresh(); } }
the answer doesn't have how fix code, if there's simpler way it? better.
this apply wp8 webbrowser apply case too. register navigating event. event cancelable if when handle event set e.cancel=true , prevent navigation
private void onnavigating(object sender, navigatingeventargs e) { //take uri string, not sure right method name string uri = e.uri.absoluteuri; if (uri.startswith("mailto")) e.cancel = true; }
Comments
Post a Comment