Open links in the default browser
The editor opens a clicked link in the user's default browser or mail app: a click in preview, Ctrl+Click while editing. Handle HtmlElementClicked only when you want your own links to open your own screens.
Built in: no code needed
The WPF HTML Editor opens a clicked link in the user's own default browser or mail app:
- In preview (
EditorModes.ReadOnlyPreview): a click opens the link and the editor keeps showing your document. Every click works, and no Internet Explorer window appears. - While editing (
EditorModes.WysiwygDesign): a plain click places the caret in the link so the user can change it, and Ctrl+Click opens it.
Only web (http, https) and mail (mailto) addresses are opened. Other addresses, such as file: paths or custom protocols, are never handed to Windows, because a document can name a program there. Links to an anchor in the same document (#section) scroll the preview as usual.
Events in preview
HtmlElementClicked does not fire in preview; it reports clicks in the editing view. GetThePreviewWebBrowser().Navigating still fires for a link that would replace the preview, after the editor has opened it, so e.Cancel is already true. If you log navigations, check it, and do not open the link a second time.
Route your own links while editing
To send your application's own links, for example crm://customer/42, to a screen in your application, handle HtmlElementClicked in the editing view and set e.EventData.returnValue to false. Set Options.FireHtmlElementClickEventFor to HtmlElementTypes.Hyperlink so the event fires only for links; a click on formatted text inside a link reports the link itself.
using System;
using SpiceLogic.HtmlEditor.Abstractions;
using SpiceLogic.HtmlEditor.WPF.EditorEventArgs;
// In the window constructor, after InitializeComponent():
MyEditor.Options.FireHtmlElementClickEventFor = HtmlElementTypes.Hyperlink;
MyEditor.HtmlElementClicked += MyEditor_HtmlElementClicked;
private void MyEditor_HtmlElementClicked(object sender, HtmlElementClickedEventArgs e)
{
string href = e.ClickedElement.getAttribute("href", 0) as string;
if (href == null || !href.StartsWith("crm://", StringComparison.OrdinalIgnoreCase))
return; // web and mail links keep the built-in behavior
e.EventData.returnValue = false; // cancel the default click handling
MyAppRouter.Open(href); // open your own screen
}Imports System
Imports SpiceLogic.HtmlEditor.Abstractions
Imports SpiceLogic.HtmlEditor.WPF.EditorEventArgs
' In the window constructor, after InitializeComponent():
MyEditor.Options.FireHtmlElementClickEventFor = HtmlElementTypes.Hyperlink
AddHandler MyEditor.HtmlElementClicked, AddressOf MyEditor_HtmlElementClicked
Private Sub MyEditor_HtmlElementClicked(sender As Object, e As HtmlElementClickedEventArgs)
Dim href As String = TryCast(e.ClickedElement.getAttribute("href", 0), String)
If href Is Nothing OrElse Not href.StartsWith("crm://", StringComparison.OrdinalIgnoreCase) Then Return
e.EventData.returnValue = False ' cancel the default click handling
MyAppRouter.Open(href) ' open your own screen
End SubThe editor attaches the event on the next selection change while a handler is subscribed, so a handler added after the document is shown takes effect from the user's next click.
Security note
If your handler opens addresses itself, allow only the schemes you expect (http, https, mailto) and never pass a raw href to Process.Start with UseShellExecute = true: a document can name a file path, shell: or a custom protocol handler that runs a program. The editor's own handling follows this rule.
WinForms
The WinForms HTML Editor behaves the same way. See Open links in the default browser for the WinForms events.
Ask your AI to do this
Connect the SpiceLogic MCP server, then give your coding assistant this prompt.
I use the SpiceLogic WPF HTML Editor. Preview links and Ctrl+Click already open in the default browser. Help me route my application's own link scheme, such as crm://, to my own screens from the editing view with HtmlElementClicked. Confirm the exact API names, types and defaults with the SpiceLogic MCP documentation, then show the changes for my project.