Hi,
If a visitor closes/pressing back on my page(my site only has one page) I want to open a popup with a question. Depending on the answer given, I want to open a new web page.
I have limited to no javascript knowledge, but what I wanted to achieve didn't seem to be difficult when I started...
However, after spending a fair few hours searching on Google and trying several "solutions" I came the following code:
<html>
<head>
<script language="JavaScript" type="text/javascript">
function confirmit() {
var closeit= confirm("The question?");
if (closeit == true) {
window.open("http://www.thenewpagethatopens.com");
}
}
</script>
</head>
<body onbeforeunload="confirmit();">
</body>
</html>
This works fine in Firefox and IE 6. In IE 7, 8 and Chrome it shows the popup with the question but nothing happens if you press Yes.
There must be a way to achieve this without using to much complicated javascript code (sticking to the default confirm should do the trick)?