I am on a work intranet only having to support IE8. I am creating a page called “watch video” which (as the name suggests) serves a video to the client. A page linking to a video will open this page in a popup with the link in the url. The person accessing the video (and a datetime stamp) is then logged into the database.
The page is just a simple “Your video will start momentarily, otherwise click here” with the click here having a href of FILE:\sharedDrive:somePathsomeVideo.wmv
. I then automatically open the video by running document.getElementById('anchor').click()
to click the anchor. The video then opens in Windows Media Player and i then want to do window.close()
.
But the page has changed to a blank page because I have clicked the anchor. Do you know how I could close the page after it has redirected? I am trying this:
<script type="text/javascript"> document.getElementById('watchVideo').click(); self.close(); </script>
Advertisement
Answer
The best solution that i found (inspired by PualPRO’s answer) was this
<a id="myAnchor" href="FILE:\sharedDrive:somePathsomeVideo.wmv" target="myIframe" onclick="setTimeout(function(){window.close()}, 5000)">Watch Video</a> <iframe name="myIframe" style="display:none;"></iframe> <script> document.getElementById('myAnchor').click(); </script>
So then on load it automatically clicks the anchor to trigger then events. I put the window.close()
inside a setTimeout
so that the page had time to load the href before closing itself. Otherwise it would close before opening the file.