I have a page in which I have placed XsltListView web part to show the view of the picture library.
Above that view I have placed a link using Content Editor Web Part which redirects to other web page with the query string parameter.
The function of OnClick event of the link in Content Editor Webpart is defined in the separate JavaScript file in Style Library.
I want to get selected item ids in the JavaScript and send it as query string parameters to the other page.
HTML tag in the content editor web part is:
<a onclick="redirectToDownloadsPage()" href="#"> Download Images </a>
The function which is in separate JavaScript file is:
function redirectToDownloadsPage() {
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");
}
}
My problem is that if I place the above script in Content Editor Web part, it works fine, but if put it in the other JavaScript file and load in the page then its not working.
I am getting items
blank, i.e. there is not value fetched in the items
.
What am I missing?
<script>
tag in thePlaceHolderAdditionalPageHead
in the Page Layout. My tag is :<script type="text/javascript" language="javascript" src='<asp:Literal runat="server" Text="<%$SPUrl:~SiteCollection/Style Library/Scripts.js%>" />'></script>
And I checked that the Scripts.js is loaded success fully on the page. @AmadeoGallardo