0

I am able to read the Site Contents. But the redirecting link is not working. To get the hyperlink what can I do in my code.

Below is my code:

<script src=""></script>  
<div id="outputInfo"></div>  
<script type="text/javascript">  
    $(document).ready(function() {  
        jQuery.ajax({  
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/AppTiles,Thumbnail",  
            method: "GET",  
            headers: {  
                "Accept": "application/json; odata=verbose"  
            },  
            success: function(data) {  
                var appTiles = data.d.results;  
                console.log(appTiles);  
                var tempValue = "<h2>Site Contents</h2><br/>";  
                appTiles.forEach(function(app) {  
                    tempValue += app.Title + " <br/>";  
                });  
                $("#outputInfo").html(tempValue);  
            },


        error: function(data) {  
            console.log(data);  
        }  
    });  
})  

output:

enter image description here

1

Please try below code to fetch the URL too:

<script src=""></script>  
<div id="outputInfo"></div>  
<script type="text/javascript">  
    $(document).ready(function() {  
        jQuery.ajax({  
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/AppTiles",  
            method: "GET",  
            headers: {  
                "Accept": "application/json; odata=verbose"  
            },  
            success: function(data) {  
                var appTiles = data.d.results;  
                console.log(appTiles);  
                var tempValue = "<h2>Site Contents</h2><br/>";  
                appTiles.forEach(function(app) {  
                    tempValue += app.Title + ":- " + _spPageContextInfo.webAbsoluteUrl + app.Target + " <br/>";  
                });  
                $("#outputInfo").html(tempValue);  
            },


        error: function(data) {  
            console.log(data);  
        }  
    });  
})  
2
  • I achieved through: appTiles.forEach(function(app) { var url=app.Target; tempValue +="<a href='" + url + "'>"+ app.Title + "</a>" + "<br />"; }); – Liz Jun 8 '20 at 12:48
  • Yes, you can set the URL using "app.Target" as your requirement. In the above, I have mentioned the URL besides each app title. Please accept it as answer. – Divya Sharma Jun 8 '20 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.