Fix for window.open() links and replaced lines with a for-loop (2)

Updated functionality to get links and files from javascript:window.open() links.
Also replaced a few lines with a for-loop.