页面重定向后 window.close()

发布于 2024-11-29 17:18:28 字数 574 浏览 2 评论 0原文

我所在的工作内部网只需支持 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

靑春怀旧 2024-12-06 17:18:28

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.

不顾 2024-12-06 17:18:28

我假设你是在 IE 或者 Firefox 中这样做?

document.getElementById('anchor').onclick = "window.open('FILE:\\sharedDrive:\somePath\someVideo.wmv'); window.close()";

或者用 return false; 代替 window.close(),让页面知道不要执行默认操作。

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.

撩起发的微风 2024-12-06 17:18:28

我发现的最佳解决方案(受到 PualPRO's 答案的启发)是这样的

<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>

,然后在加载时它会自动单击锚点来触发事件。我将 window.close() 放入 setTimeout 中,以便页面在自行关闭之前有时间加载 href。否则它会在打开文件之前关闭。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文