Skip to main content

SetHyperlink

Sets a hyperlink to the current drawing object (shape or image).

Pass null to remove the hyperlink.

Inherited from ApiDrawing.SetHyperlink.

Syntax​

expression.SetHyperlink(hyperlink);

expression - A variable that represents an ApiChart class.

Parameters​

NameRequired/OptionalData typeDefaultDescription
hyperlinkRequiredApiHyperlink | nullThe hyperlink object to be set to the drawing, or null to remove the hyperlink.

Returns​

boolean

Example​

Add clickable links to shapes and images in a presentation.

// How do I add a hyperlink to a shape or image in a presentation?

// Attach a web link to a shape and a slide link to an image in a presentation.

const presentation = Api.GetPresentation();
presentation.AddSlide(Api.CreateSlide());

const slide = presentation.GetSlideByIndex(0);
slide.RemoveAllObjects();

const fill = Api.CreateSolidFill(Api.HexColor('#e2e4f6'));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape('rect', 150 * 36000, 150 * 36000, fill, stroke);
slide.AddObject(shape);

const image = Api.CreateImage(
'https://static.onlyoffice.com/assets/docs/samples/img/onlyoffice_logo.png',
150 * 36000, 150 * 36000
);
image.SetPosition(160 * 36000, 0);
slide.AddObject(image);

const urlHyperlink = Api.CreateHyperlink('https://www.onlyoffice.com', 'Link to ONLYOFFICE website');
const pageHyperlink = Api.CreateHyperlink('ppaction://hlinksldjumpslide1', 'Link to the second slide');
shape.SetHyperlink(urlHyperlink);
image.SetHyperlink(pageHyperlink);