页面重定向后 window.close()
我所在的工作内部网只需支持 IE8。我正在创建一个名为“观看视频”的页面,该页面(顾名思义)向客户端提供视频。链接到视频的页面将在弹出窗口中打开此页面,其中的链接包含在 url 中。然后,访问视频(和日期时间戳)的人将登录到数据库中。
该页面只是一个简单的“您的视频将立即开始,否则请单击此处”,其中单击此处的 href 为 FILE:\\sharedDrive:\somePath\someVideo.wmv
。然后,我通过运行 document.getElementById('anchor').click()
单击锚点来自动打开视频。然后视频在 Windows Media Player 中打开,然后我想要执行 window.close()
。
但由于我点击了锚点,页面已变为空白页。您知道重定向后如何关闭页面吗?我正在尝试这个:
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将
target="_blank"
添加到您的标记,以便它在新的单独窗口中打开(该窗口在播放后可见之前会自动关闭)在 Windows Media Player 中)。然后您也可以关闭当前窗口。
Add
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.我假设你是在 IE 或者 Firefox 中这样做?
或者用
return false;
代替window.close()
,让页面知道不要执行默认操作。I'm assuming you are doing this in IE or maybe firefox?
or instead of
window.close()
do areturn false;
that will let the page know not to do the default.我发现的最佳解决方案(受到 PualPRO's 答案的启发)是这样的
,然后在加载时它会自动单击锚点来触发事件。我将
window.close()
放入setTimeout
中,以便页面在自行关闭之前有时间加载 href。否则它会在打开文件之前关闭。The best solution that i found (inspired by PualPRO's answer) was this
So then on load it automatically clicks the anchor to trigger then events. I put the
window.close()
inside asetTimeout
so that the page had time to load the href before closing itself. Otherwise it would close before opening the file.