admin管理员组文章数量:1415145
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:\somePath\someVideo.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>
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:\somePath\someVideo.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>
Share
Improve this question
edited May 8, 2021 at 17:34
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked Aug 15, 2011 at 5:24
Timothy RuhleTimothy Ruhle
7,60710 gold badges44 silver badges68 bronze badges
3 Answers
Reset to default 3Add target="_blank"
to your <a>
tag so that it opens in a new separate Window (Which the browser will automatically close before it is visible since it plays it in Windows Media Player). Then you can close the current window as well.
I'm assuming you are doing this in IE or maybe firefox?
document.getElementById('anchor').onclick = "window.open('FILE:\\sharedDrive:\somePath\someVideo.wmv'); window.close()";
or instead of window.close()
do a return false;
that will let the page know not to do the default.
The best solution that i found (inspired by PualPRO's answer) was this
<a id="myAnchor" href="FILE:\\sharedDrive:\somePath\someVideo.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.
本文标签: javascriptwindowclose() after page redirectStack Overflow
版权声明:本文标题:javascript - window.close() after page redirect - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745199060a2647282.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论