How Do I Open a Pop Up Window over Destination URL

2019-09-20 01:49发布

问题:

I want to link to a url and after the destination page opens, pop up a window over it. I've seen some examples of this but don't know how to code it. I'm a .NET developer but perhaps this needs javascript? Anyone know how to do it?

Page 1

Link 2 Page 2 ---> Page 2 opens... Popup opens over Page 2.

Thanks.

回答1:

Approach #1:

In Page 2:

<script>
if (document.referrer === "URL of Page 1 goes here")
{
    window.open("URL of popup goes here", "_blank");
}
</script>

Thus the popup will only appear if you arrived at Page 2 via a link from Page 1.

Approach #2 (if you cannot modify Page 2):

In Page 1:

<script>
    function page2popup()
    {
        window.open("URL of popup goes here", "_blank");
    }
</script>
<a href="URL of Page 2 goes here" onclick="page2popup();">Page 2</a>


回答2:

if you are doing this in html, then

page1.html

<html>
<head>

</head>
<body>
    <a href="page2.html">click to go to page to page2</a>
</body>
</html>

page2.html

<html>
<head>
    <script type="text/javascript">
    function popup(){
        //alert("this is page 2");
        window.open("http://www.geekzgarage.com"); 
    }
    </script>
</head>
<body onload="popup()">
    this is page 2 and popup window is opened as provided in the link given..
</body>
</html>