简体   繁体   中英

Popup Window not working

I am trying to make a window pop up when the "popup" button is pressed as a part of my Javascript assignment for school but can't figure out why my code isn't working. I've assigned the popup button to a jQuery selector and it still will not open.

<html>
<head>
<title>Adam Ginther's Pop-up Window</title>
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="panel">
Congrats! You won!
</div>
<div id="centreblock">
<h1>WOW! AMAZING!!!</h1>
<img src="images/ipad.gif" width="100%" height="250">
<p>Congratulations! You won a free iPad! Enter your name, address, and phone number to have it delivered now.
<form action="">
<br>
<label for="firstName">First Name: </label>
<input type="text" size="12" id="firstName" name="firstName">
<br>
<br>
<label for ="lastName">Last Name: </label>
<input type="text" size"12" id="lastName" name="lastName">
<br>
<br>
<label for="address">Address: </label>
<input type="text" size="12" id="address" name="address">
<br>
<br>
<label for="phoneNum">Phone Number: </label>
<input type="text" size="12" id="phoneNum" name="phoneNum">
</form>
<br>
<a href="#" id="popup"><br>REDEEM THIS SPECTACULAR OFFER NOW!</a>
<br>
</div>
<script src="http//code.jquery.com/jquery-latest.min.js"></script>
<script src="js/script.js"></script>
</body>
</html>


//script.js
var new_win;
var firstName;
var lastName;
var address;
var phoneNumber;

function newWindow() { 
    firstName = $('#firstName').val();
    if (firstName !='') {
    window.open('popup.html');
    } else {
        $('#firstName').addClass('error');
    };
    $(function() {
        $('#popup').click(function() {
            newWindow();
        });
    });
};

try this:

<html>
<head>
<title>Adam Ginther's Pop-up Window</title>
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/style.css">

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="js/script.js"></script>
<script language="javascript">


//script.js
var new_win;
var firstName;
var lastName;
var address;
var phoneNumber;

function popitup(url) {
    newwindow=window.open(url,'name','height=200,width=150');
    if (window.focus) {newwindow.focus()}
    return false;
}

function newWindow() { 
    firstName = $('#firstName').val();
    if (firstName !='') {
    popitup('popup.html');
    } else {
        $('#firstName').addClass('error');
    };
};

    $(document).ready(function(){
        $('#popup').click(function() {
            newWindow();
        });
    });
</script>
</head>
<body>
<div id="panel">
Congrats! You won!
</div>
<div id="centreblock">
<h1>WOW! AMAZING!!!</h1>
<img src="images/ipad.gif" width="100%" height="250">
<p>Congratulations! You won a free iPad! Enter your name, address, and phone number to have it delivered now.
<form action="">
<br>
<label for="firstName">First Name: </label>
<input type="text" size="12" id="firstName" name="firstName">
<br>
<br>
<label for ="lastName">Last Name: </label>
<input type="text" size"12" id="lastName" name="lastName">
<br>
<br>
<label for="address">Address: </label>
<input type="text" size="12" id="address" name="address">
<br>
<br>
<label for="phoneNum">Phone Number: </label>
<input type="text" size="12" id="phoneNum" name="phoneNum">
</form>
<br>
<a href="javascript:void(0)" id="popup"><br>REDEEM THIS SPECTACULAR OFFER NOW!</a>
<br>
</div>
</body>
</html>

please note:

  • The jquery version was outdated
  • there are some changes done in the javascript function

I hope this might help. You can edit as per your flow and requirement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM