Forum Discussion
Force ALL items in Resource Tab to open in popup window
We had an issue where items in the resource tab would open on the main browser window and then "push" the course "behind" the main browser window - making the learner think the course 'went away'.
This script looks for ALL anchor tags and then forces them to open in popup windows - solving this issue.
Simply put it in your Slide Master as a javascript trigger on slide start
________________________
//THIS GETS ALL OF THE ANCHORS ON THE PAGE
var listedResources = document.getElementsByTagName('a');
//FOR ALL OF THE ANCHORS
for (i = 0; i < listedResources.length; i++) {
//WE RETRIEVE THE LINK (HREF) AS ORIGINALLY DEFINED BY STORYLINE
var thisDocHREF = listedResources[i]['href'];
//WE CHECK TO SEE IF THE STRING INCLUDES A %27 (WHICH IS THE EQUILAVENT OF A SINGLE QUOTE MARK)
if( thisDocHREF.includes('%27') ){
//IF IT DOES THE WE GRAB THE STRING FROM THE FIRST SINGLE QUOTE TO THE %27 - THEN ADD A SINGLE QUOTE
var Doc2open = thisDocHREF.substring(thisDocHREF.indexOf("'"),thisDocHREF.indexOf('%27')) + "'";
}
else{
//IF IT DOESN'T THEN WE JUST GRAB THE STRING FROM THE FIRST QUOTE UNTIL THE END AND THEN ADD A SINGLE QUOTE
var Doc2open = thisDocHREF.substring(thisDocHREF.indexOf("'"),thisDocHREF.lastIndexOf("'")) + "'";
}
//WE THEN REPLACE THE EXISTING LINK (HREF) CALL WITH THE NEW FUNCTION TO OPENT HE LINK IN A NEW POPUP WINDOW
listedResources[i].setAttribute('href', "javascript:window.open(" + Doc2open + ",'_blank','height= 600', 'width= 800','resizable=yes','scrollbars=yes','toolbar=yes','menubar=yes','location=yes')");
}
_________________
- BobStrykerCommunity Member
This is a great capability, Peter. Thanks for sharing it.
Could this JavaScript trigger be extended to hyperlink triggers on regular content slides?
- StephenLee-5159Community Member
Peter, this is an excellent solution as we were experiencing issues on our LMS with Resource documents opening up and hiding the course leaving users confused how to get back to their course.
My only question is should this work with any hyperlink that is on a course page? It just seems to work for me for those documents in the Resource tab (as best practice, I do usually only use the Resources tab for users to open documents though). If I have a hyperlink on a Layer to open a .pdf, I shouldn't have to execute the Javascript on the Layer should I? I assume just having it on the Master slide should cover this?
Thanks!
- PeterSorenson-7Community Member
Well - I only wrote it to address the Resources items as that was the problem we were having (the linked items were opening in tabs)
Yes - we just insert it on the Master Slide so it loops thru all of the items in the Resources and rewrites the popup code.
The ANSWER to LINKS on a page is to ensure the popup window is set to Window Size: CUSTOM in the New Browser Window Properties. If you leave it Default then those links open up in tabs as well... - StephenLee-5159Community Member
Brilliant! Changing Window Size to Custom fixes issue with hyperlinks on course pages. I can't tell you how many emails and phone calls are taken by our LMS team from students who complain that they got booted out of their course after opening up a hyperlinked document or Resource document.
Many thanks.