Vwa.Shape.getHyperlinks Method

Applies to: apps for SharePoint | SharePoint Server 2013

Returns an array of anonymous objects, each of which specifies a hyperlink that is associated with the shape.

var value = Shape.getHyperlinks()

Return value

Object[] An array of anonymous objects, each of which specifies a hyperlink that is associated with the shape.

If there are no hyperlinks associated with the shape, the method returns an empty array.

Remarks

Each anonymous object in the array that is returned has the following properties:

description A string that describes the hyperlink.

value A string that specifies the URL of the hyperlink.

The primary shape's hyperlink is placed first in the array.

For more information about how to add a Visio Web Access Web Part to a SharePoint Web Parts page, see Customizing Visio Web Drawings in the Visio Web Access Web Part.

Example

The following example adds a handler to the Vwa.shapeselectionchanged event. When the event is raised, the code sample gets the hyperlinks applied to the shape that raised the event and then displays them in the Content Editor Web Part.

<script type="text/javascript">

document.write("Hyperlinks contained in this shape:");
document.write("<div id='shapelinks'></div>");

// Declare the global variables for the Visio Web Access web part, the active page in the web part,
// the shapes on the active page, and the <div> tag in the Content Editor Web Part.
var vwaControl;
var vwaPage;
var vwaShapes;
var linkList;

// Add a handler to the AJAX Sys.Application.load event.
Sys.Application.add_load(onApplicationLoad)

// Capture a reference to the current session of the Visio Web Access Web Part.
function onApplicationLoad() {
    try{
            vwaControl= new Vwa.VwaControl(getVWAWebPartID());
            vwaControl.addHandler("diagramcomplete", onDiagramComplete);
    }
    catch(err){
        alert(err);
    }
}

// Search the SharePoint page to get the WebPartID# for the Visio Web Access Web Part.
function getVWAWebPartID() {
    
    // Get a NodesList of all the div tags on the page. 
    var divArray = document.getElementsByTagName("div");
    var webPartElementID;
    
    // Iterate through the NodesList to get the node with the class attribute "VisioWebAccess."
    for (var i = 0; i < divArray.length; i++) {
        var node = divArray[i];
        
        // Return the first instance of the Visio Web Access Web Part.
        if (node.className == "VisioWebAccess") {
            webPartElementID = node.parentNode.parentNode.id;
            break;
        }
    }
    return webPartElementID;
}

// Capture references to global variables and add handler functions to events.
function onDiagramComplete(){
    try{
        // Set the vwaPage and vwaShapes variables to the active page and the shapes collection on that page, respectively.
        vwaPage = vwaControl.getActivePage();
        vwaShapes = vwaPage.getShapes();
        linkList = document.getElementById("shapelinks");

        // Remove the handler from the shape selection changed event and then add it back to the event.
        vwaControl.removeHandler("shapeselectionchanged", onShapeSelectionChanged);
        vwaControl.addHandler("shapeselectionchanged", onShapeSelectionChanged);
        
    }
    catch(err){
        alert(err);
    }
}

// Get the hyperlinks from a shape when the selection changes and display them in the Content Editor Web Part.
function onShapeSelectionChanged(source, args){
    try{
        // Clear any displayed links from the Content Editor Web Part.
        linkList.innerHTML = "";

        // Get the array of hyperlinks from the selected shape.
        var vwaShape = vwaShapes.getItemById(args);
        var newURLArray = vwaShape.getHyperlinks();

        // Check to see whether the shape has any hyperlinks.
        if (newURLArray.length > 0) {
            
            // Iterate through all the links applied to the shape.
            for (var i = 0; i < newURLArray.length; i++) {
                
                // Get the anonymous object from the array.
                currLink = newURLArray[i];

                // Get the URL for the hyperlink.
                var newURL = currLink.value;
                var newLink;
                var newText;

                // Check if the link goes to another page in the drawing.
                if (newURL.indexOf("vdw") >= 0) {
                    
                    // Create a paragraph element for a link to a page.
                    newLink = document.createElement("p");

                }
                else {
                    
                    // Create a hyperlink element for a link to a Web address.
                    newLink = document.createElement("a");
                    newLink.setAttribute("href", newURL);
                    newLink.setAttribute("target", "_blank");
                }

                // Check if there is a description for the hyperlink.
                if (currLink.description) {
                    newText = document.createTextNode(currLink.description);
                }
                else {
                    newText = document.createTextNode(newURL);
                }

                // Add the link, link text, and a line break to the <div> tag in the Content Editor Web Part.
                var lineBreak = document.createElement("br");
                linkList.appendChild(newLink);
                newLink.appendChild(newText);
                linkList.appendChild(lineBreak);

            }
        }
    }
    catch(err){
          alert(err);
    }
}

</script>

See also

Reference

Vwa.Shape Class

Vwa.Shape Class Methods