javascript - window.close() after page redirect - Stack Overflow

I am on a work intranet only having to support IE8. I am creating a page called "watch video"

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
Add a ment  | 

3 Answers 3

Reset to default 3

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.

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745199060a4616235.html

相关推荐

  • javascript - window.close() after page redirect - Stack Overflow

    I am on a work intranet only having to support IE8. I am creating a page called "watch video"

    5小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信