Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
dhavalu
Frequent Visitor

Hyperlink not clickable with custom visual.

Hello,

I am working on creating custom visual which creats simple hyperlink using d3js.

Some how when its clicked it dosent open the browser even though the link has proper href and target tags.

I also tried by giving the column appropriate Data Category of Web Url.

Is this due to any security reasons?

Isnt that possible in custom visual?

9 REPLIES 9
Luisa
New Member

For anyone still searching for the answer to this (as I was), there is a utility in Power BI to do this called Launch URL. You can use it as simply as follows.

 

.on("click", data => {
     (d3.event as MouseEvent).preventDefault();
     this.host.launchUrl("https://example.com/" + data.<yourField>);
});
 

 

Here are the docs about it:

https://github.com/Microsoft/PowerBI-visuals/blob/master/Tutorial/LaunchURL.md

Sreejith
Frequent Visitor

The following code worked for me while trying to create a custom visual that have a Resolve link which redirects to an API on click. I used the default YourVisual template and added the link as 

tr.selectAll("td")
.data(d=> d)
.enter().append("td")
.attr('data-th',(d, i) => viewModel.categories[i].value)
.text(d => this.format(d)).append('a')
.attr("href", "https://www.google.com")
.attr("target","_top")
.text(" Resolve");

 

Hope this helps.

This doesn't work for me (either _top or _blank) in both designer and portal

vincent_1234
Helper I
Helper I

It is because of sandboxed iframes are blocking this behavior

 

When clicking hyperlink:

Blocked opening url in a new window because the request was made in a sandboxed frame whose 'allow-popups' permission is not set.

 

When embedding in iframe:

Refused to display url in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

Hey Vincent, Thanks for the reply.

 

Is there any alternative to this. How come the exiting table control render link tag when the column is "Web Url"? Any Idea?

 

Thanks.

I have not found any alternative.

Native visuals can use urls because they are not sandboxed in iframes.

I understand Microsoft does this for safety so improper developed custom visuals can't collide but it would be nice if we wern't limited in functionality.

Yes. There are certain restrictions with the desktop version and web version like link, loading scripts etc.

Thanks for the insight.

 

Desktop Power Bi restricts hyperlinks.

Below code works for Power Bi Web.

 

var val = 'https://powerbi.microsoft.com';

tr.append("td").append("a").attr("href", val).attr("title", val).attr("target", "_blank").text(val);

 

Make sure that url is valid http or https protocol. Without the protocol the link would try searching within subdomain of https://app.powerbi.com and the page wont get displayed.

 

Try this out.

I got a solution on last Friday 30. Sep 2016.

 

I try out window.open in the onClick method. 

            bars.on('click', function(d) {
                selectionManager.select(d.selectionId).then((ids: ISelectionId[]) => {
                    bars.attr({
                        'fill-opacity': ids.length > 0 ? BarChart.Config.transparentOpacity : BarChart.Config.solidOpacity
                    });
                    window.top.location.href = "https://www.google.com";
                    //window.open("https://google.de");
                    d3.select(this).attr({
                        'fill-opacity': BarChart.Config.solidOpacity
                    });
                });

                (<Event>d3.event).stopPropagation();
            });

            bars.exit()
               .remove();

 

But today i got the sandbox error in my chrome console. Did the Power BI Developer change something on the IFrame?

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.