|
1 | 1 | --- |
2 | 2 | layout: post |
3 | | -title: Using Hyperlinks in Blazor DocumentEditor Component | Syncfusion |
| 3 | +title: Hyperlink in Blazor DocumentEditor Component | Syncfusion |
4 | 4 | description: Checkout and learn here all about Hyperlink and its functionality in Syncfusion Blazor DocumentEditor component and more. |
5 | 5 | platform: document-processing |
6 | 6 | control: DocumentEditor |
7 | 7 | documentation: ug |
8 | 8 | --- |
9 | 9 |
|
10 | | -# Using Hyperlinks in Blazor DocumentEditor Component |
| 10 | +# Hyperlink in Blazor DocumentEditor Component |
11 | 11 |
|
12 | 12 | A hyperlink is a reference in a document that links content to another location, such as a web page, an email address, or a bookmark within the same document. The [Blazor Word Processor](https://www.syncfusion.com/blazor-components/blazor-word-processor) (Document Editor) provides comprehensive support for creating, editing, and customizing hyperlinks. |
13 | 13 |
|
14 | | -## Creating and Editing Hyperlinks via the UI |
15 | | - |
16 | | -The user interface offers intuitive ways to add and manage hyperlinks. |
17 | | - |
18 | | -### Automatic Hyperlink Creation |
19 | | - |
20 | | -The Document Editor can automatically format a URL as a hyperlink. Simply type an address and press `ENTER`, `SPACEBAR`, or `TAB`. The text will be converted to a functional hyperlink if it begins with one of the following prefixes: |
21 | | - |
22 | | -* http:// |
23 | | -* https:// |
24 | | -* file:/// |
25 | | -* www. |
26 | | -* mail to: |
27 | | - |
28 | | -### Using the Hyperlink Dialog |
29 | | - |
30 | | -For more control, the component includes a built-in dialog for inserting and editing hyperlinks. To open it, place the cursor on the desired text and press `Ctrl+K`. |
31 | | - |
32 | | -The dialog allows you to: |
33 | | -* Link to an existing web page or file by entering its URL. |
34 | | -* Link to an email address. |
35 | | -* Link to a bookmark within the current document. |
36 | | - |
37 | | -You can also open the dialog programmatically: |
38 | | - |
39 | | -```csharp |
40 | | -@* The following code example demonstrates how to open the hyperlink dialog. *@ |
41 | | -container.DocumentEditor.OpenDialog(DialogType.Hyperlink); |
42 | | -``` |
43 | | - |
44 | | -## Managing Hyperlinks Programmatically |
45 | | - |
46 | | -The Document Editor exposes a rich set of APIs for managing hyperlinks in code. |
47 | | - |
48 | | -### Insert a Hyperlink |
49 | | - |
50 | | -Use the `InsertHyperlinkAsync` method to create a hyperlink at the current selection. You can specify both the destination URL and the display text. |
51 | | - |
52 | | -```csharp |
53 | | -@* The following code example demonstrates how to insert a hyperlink to "https://www.google.com" with the display text "Google". *@ |
54 | | -await container.DocumentEditor.Editor.InsertHyperlinkAsync("https://www.google.com", "Google"); |
55 | | -``` |
56 | | - |
57 | | -### Remove a Hyperlink |
58 | | - |
59 | | -To remove a hyperlink and convert it back to plain text, use the `RemoveHyperlinkAsync` method. This can also be done by pressing the `Backspace` key at the end of the hyperlinked text. |
60 | | - |
61 | | -```csharp |
62 | | -@* The following code example demonstrates how to remove a hyperlink from the current selection. *@ |
63 | | -await container.DocumentEditor.Editor.RemoveHyperlinkAsync(); |
64 | | -``` |
65 | | - |
66 | | -### Copy a Hyperlink's URL |
67 | | - |
68 | | -To copy the destination URL of a hyperlink to the clipboard, use the `CopyHyperlinkAsync` method. |
69 | | - |
70 | | -```csharp |
71 | | -@* The following code example demonstrates how to copy the URL of the hyperlink at the current selection. *@ |
72 | | -await container.DocumentEditor.Selection.CopyHyperlinkAsync(); |
73 | | -``` |
74 | | - |
75 | | -## Customizing Hyperlink Navigation |
| 14 | +## Navigate a hyperlink |
76 | 15 |
|
77 | 16 | By default, clicking a hyperlink navigates to its destination. This behavior can be customized using the `OnRequestNavigate` event. |
78 | 17 |
|
79 | 18 | This event is triggered when a user `Ctrl+Clicks` a hyperlink, providing details about the link type and destination. You can intercept this action to define custom logic, such as opening the link in a new tab or handling it within your application. |
80 | 19 |
|
81 | 20 | Setting `args.IsHandled = true` prevents the editor's default navigation action from executing, giving you full control over the process. |
82 | 21 |
|
| 22 | +### Add the OnRequestNavigate event for DocumentEditor |
| 23 | + |
| 24 | +The following example illustrates how to add OnRequestNavigate event for DocumentEditor. |
| 25 | + |
83 | 26 | ```cshtml |
84 | 27 | <SfDocumentEditor ID="cont" IsReadOnly="false" EnableEditor="true" EnableSelection="true" @ref="container" Height="590px"> |
85 | 28 | <DocumentEditorEvents OnRequestNavigate="OnRequestNavigate" Created="OnCreated"></DocumentEditorEvents> |
@@ -119,6 +62,61 @@ Setting `args.IsHandled = true` prevents the editor's default navigation action |
119 | 62 | You can also programmatically trigger navigation for the hyperlink at the current selection by calling the `NavigateHyperlinkAsync` method. |
120 | 63 |
|
121 | 64 | ```csharp |
122 | | -@* The following code example demonstrates how to trigger navigation for the selected hyperlink. *@ |
123 | 65 | await container.DocumentEditor.Selection.NavigateHyperlinkAsync(); |
124 | | -``` |
| 66 | +``` |
| 67 | +### Copy Hyperlink |
| 68 | + |
| 69 | +To copy the destination URL of a hyperlink to the clipboard, use the `CopyHyperlinkAsync` method. |
| 70 | + |
| 71 | +```csharp |
| 72 | +await container.DocumentEditor.Selection.CopyHyperlinkAsync(); |
| 73 | +``` |
| 74 | + |
| 75 | +### Add Hyperlink |
| 76 | + |
| 77 | +The Document Editor can automatically format a URL as a hyperlink. Simply type an address and press `ENTER`, `SPACEBAR`, or `TAB`. The text will be converted to a functional hyperlink if it begins with one of the following prefixes: |
| 78 | + |
| 79 | +* http:// |
| 80 | +* https:// |
| 81 | +* file:/// |
| 82 | +* www. |
| 83 | +* mail to: |
| 84 | + |
| 85 | +Use the `InsertHyperlinkAsync` method to create a hyperlink at the current selection. You can specify both the destination URL and the display text. |
| 86 | + |
| 87 | +```csharp |
| 88 | +await container.DocumentEditor.Editor.InsertHyperlinkAsync("https://www.google.com", "Google"); |
| 89 | +``` |
| 90 | + |
| 91 | +### Remove Hyperlink |
| 92 | + |
| 93 | +To remove a hyperlink and convert it back to plain text, use the `RemoveHyperlinkAsync` method. This can also be done by pressing the `Backspace` key at the end of the hyperlinked text. |
| 94 | + |
| 95 | +```csharp |
| 96 | +await container.DocumentEditor.Editor.RemoveHyperlinkAsync(); |
| 97 | +``` |
| 98 | + |
| 99 | +### Hyperlink Dialog |
| 100 | + |
| 101 | +For more control, the component includes a built-in dialog for inserting and editing hyperlinks. To open it, place the cursor on the desired text and press `Ctrl+K`. |
| 102 | + |
| 103 | +The dialog allows you to: |
| 104 | +* Link to an existing web page or file by entering its URL. |
| 105 | +* Link to an email address. |
| 106 | +* Link to a bookmark within the current document. |
| 107 | + |
| 108 | +You can also open the dialog programmatically: |
| 109 | + |
| 110 | +```csharp |
| 111 | +container.DocumentEditor.OpenDialog(DialogType.Hyperlink); |
| 112 | +``` |
| 113 | +You can use the following keyboard shortcut to open the hyperlink dialog if the selection is in hyperlink. |
| 114 | + |
| 115 | +| Key Combination | Description | |
| 116 | +|-----------------|-------------| |
| 117 | +|Ctrl + K | Open hyperlink dialog that allows you to create or edit hyperlink| |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
0 commit comments