Articles in this section
Category / Section

How To Paste URL Annotation Hyperlink in JavaScript Diagram?

2 mins read

The Syncfusion® JavaScript Diagram component allows you to dynamically configure a URL as a hyperlink during editing. By using the textEdit event, you can capture the newly entered text and, if it matches a URL pattern, convert it into a clickable hyperlink.

Below is an example demonstrating how to dynamically paste a URL as an annotation hyperlink using the textEdit event:

// Initializes the diagram control
var diagram = new ej.diagrams.Diagram({
 width: '100%',
 height: '550px',
 textEdit: function (args) {
   const urlPattern = /^(http|https|www)/; // Regular expression to match links
   if (urlPattern.test(args.newValue)) {
     // Set hyperlink properties
     args.annotation.hyperlink = {
       content: 'HyperLink content', // Set desired content for the hyperlink
       link: args.newValue, // Use the new value as the link
       hyperlinkOpenState: 'NewTab', // Open in new tab
       textDecoration: 'Underline', // Add underline to the text
     };
   }
 },
});

Sample: Click Here

Conclusion

I hope you enjoyed learning how to paste URL annotation hyperlink in JavaScript Diagram.

You can refer to our JavaScript Diagram feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

You can also explore our JavaScript Diagram example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page.

If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied