I have a publishing page in which I have placed content editor web part which contains the link to redirect the user to application page.
Code in the content editor web part is:
<script type="text/javascript">
function redirectToDownloadsPage() {
SP.SOD.executeOrDelayUntilScriptLoaded(function(){
var ctx = SP.ClientContext.get_current();
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
var myItems = '';
var i;
for (i in items) {
myItems += '|' + items[i].id;
}
if (myItems) {
var siteUrl = url = window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl + "/_layouts/15/DownloadImages.aspx?Items=" + myItems;
window.location.href = siteUrl
}
else {
alert("Select atleast one item");
}
}, "SP.js");
}
</script>
<a onclick="return redirectToDownloadsPage();" href="#"> Download Images </a>
My problem is when I edit the page and click on the link JavaScript works, then I check in the page then also the JavaScript works fine but when I publish the page the JavaScript does not work.
I am getting no items in the item
in JavaScript.
What am I missing?
Unable to get property 'Selection' of undefined or null reference
@Amit