Jaideep
Jaideep

Reputation: 41

Add hyperlink to custom visual in power bi

I am very new to Power BI Custom visual development and trying to create a custom visual in Power BI that has a simple text box and when a user clicks on the text box. He is redirected to a new web Page. In short i am trying to add a hyperlink to a visual and whenever a user clicks it a new page opens up .

Here is the code which i am using

module powerbi.extensibility.visual {
export class Visual implements IVisual {
    private svg:D3.Selection;

    constructor(options: VisualConstructorOptions) {
         this.svg=d3.select(options.element).append("svg").classed("magicbox",true);
    }

    public update(options: VisualUpdateOptions) {
         this.svg.attr({
            width:options.viewport.width,
            height:options.viewport.height
        });

        let box=this.svg.append("rect").classed("rect",true)
        box.attr({
            href:'www.google.com',
           x:50,
            y:50,
            width:800,
            height:800,
            fill:"white",
            stroke:"black"
        })
    }

    public destroy(): void {
    }
}

}

can anyone please let me know how do i add a hyperlink ?

Upvotes: 1

Views: 2491

Answers (2)

Darren Gosbell
Darren Gosbell

Reputation: 1940

There is now a launchUrl api for opening external links from a custom visual see: https://learn.microsoft.com/en-us/power-bi/developer/visuals/launch-url

Upvotes: 2

user5226582
user5226582

Reputation: 1986

This is disabled by design, PowerBI forum thread:

It is because of sandboxed iframes are blocking this behavior

You can try disabling sandboxing as described in this answer:

ou can disable sandboxing by adding this querystring:

?sandboxVisualsEnabled=false

Be aware it's used for security reasons.

There's also an option to use links in a table.

Upvotes: 0

Related Questions