Reputation: 1
I start to learn jQuery. I create a popup window and add a button on it. I want to click on that button to close my popup window, I use an id to attach my window, but it is not working. Thank you for your help.
<a href="" rel="0" class="patrick" >click me</a>
var windowSizeArray = ["width=200,height=200", "width=3000,height=400,scrollbars=yes"];
$(document).ready(function () {
$('#win').bind('click', function () {
newwindow.close();
});
var $newdiv1 = $('<input type="button" class="myButton" value="ok" id="win"/>')
$('.patrick').click(function (event) {
var url = $(this).attr("href");
var windowName = "popUp"; //$(this).attr("name");
var windowSize = windowSizeArray[$(this).attr("rel")];
var newwindow = window.open(url, windowName, windowSize);
event.preventDefault();
$(newwindow.document.body).html($newdiv1);
});
});
Upvotes: 0
Views: 2147
Reputation: 318332
Don't use inline JS much, but in this case, just adding some inline JS to the button is the easiest solution :
var windowSizeArray = ["width=200,height=200", "width=3000,height=400,scrollbars=yes"];
$(document).ready(function () {
var $newdiv1 = $('<input type="button" class="myButton" value="ok" id="win" onclick="window.close()"/>')
$('.patrick').click(function (event) {
var url = $(this).attr("href");
var windowName = "popUp"; //$(this).attr("name");
var windowSize = windowSizeArray[$(this).attr("rel")];
var newwindow = window.open(url, windowName, windowSize);
event.preventDefault();
$(newwindow.document.body).html($newdiv1);
});
});
Upvotes: 1