0

例如,下面的对话框将打开一个新窗口进行共享。由于用户分享了帖子,窗口关闭后。然后,您可以使用 javascript 从原始 url 做一个覆盖消息吗?

http://www.upworthy.com/if-you-live-in-one-of-these-states-the-impact-of-washingtons-shenanigans-is-huge

上面的网站做了这样的事情,只是不知道怎么做。如果您点击分享到 facebook,然后开箱即用“x”,您将看到在用户分享或关闭窗口后发生的覆盖。这是用javascript完成的,如果是这样怎么办?

<a class="shareonfb" style="color: #fff;text-indent: 0px;padding-left: 35px;width: 130px;padding-top: 10px;height: 24px;" onClick="window.open (this.href, 'child', 'height=400,width=665,scrollbars'); return false" href="https://www.facebook.com/sharer/sharer.php?u=http://foo.com" target="_blank">Share on Facebook</a>
4

1 回答 1

0

创建一个html文件“parent.html”并放入代码:

<!DOCTYPE html>
<html>
    <head>
        <script>
            function open_win()
            {
                myWindow=window.open('popup.html','','width=300,height=250');
                myWindow.focus();
                myWindow.onbeforeunload = WindowCloseHanlder;
            }
            function WindowCloseHanlder(){
                myWindow.close();
                window.alert('Popup is closed');
            }
        </script>
    </head>
<body>
    <h1>Welcome to my Home Page</h1>
    <a href="javascript:void(0);"  onclick="open_win()">Share on Facebook</a>
</body>
</html>

创建“popup.html”并输入以下代码:

<!DOCTYPE html>
<html>
  <head></head>
  <body>
     <h1>I am pop up</h1>
     <p>Close this window</p>
  </body>
</html>

关闭弹出窗口后,您将看到 javascript 调用。您可以调用弹出窗口而不是警报消息。

于 2013-11-10T19:53:34.120 回答