SharePoint Visual Web Part open links in the same window

The Visio Web Part in SharePoint is a great way to display your visio diagrams direstly in SharePoint.

It can also be used for other things, like displaying an interactive diagram with embedded links. This solution gives the user an ability to work with a diagram directly in Visio (no SharePoint knowledge required) and than simply upload the diagram to SharePoint, which displays it to some page for others to see.

This scenario is exactly what I was working on when I encounter a problem with the Visio Web Part.

The problem is that the Visio Web Part displays a clicked link in a context menu and always opens the link in a new window. This was not the behavior that the client wanted. Links should be opened in the same window and with now dropdows.

The solution turned out to be configuring the web part and some custom javascript.

Step 1: Configuring the Visio Web Part

Taken a simple Visio Diagram with test links

Test Visio Links

Test Visio Links

If you click on one of the links insted of directly transferring you to that link you will get a dropdown

Test Visio Links clicked

Test Visio Links clicked

Unfortunately the only fix for this behaviour is to disable of hyperlinks for the entire diagram.

This is possible in the Visio Web Part settings

Disable Hyperlink

Disable Hyperlink

Great, now we don’t have the context menu problem, but we can’t open any links. That is a bit crappy, I wil give you that. To fix this we need some javascript help.

Step 2: Custom javascript

Fortunatly for us we can implement opening links by ourselfes with javascript.

Include the below script in the page with your diagram with Script Editor Web Part for example and you are ready to go.