KacperMadej wrote:Hi cu7co77,
If you could set up a live example in JSFiddle, then we could check what might be wrong.
Best Regards,
Kacper Madej
This is the code of my main page:
<!DOCTYPE html>
<html lang="nl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<script src="jquery.js" type="text/javascript"></script>
<script src="highslide-full.js" type="text/javascript"></script>
<link href="highslide.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div>
<a href="iframepage.htm" class="highslide" onclick="return hs.htmlExpand(this{objectType:'iframe',width:604,height:476})"><img src="myimage.jpg" alt="my image" width="240" height="160"></a></div>
</body>
</html>
This is the code of iframepage.htm:
<!DOCTYPE html>
<html lang="nl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Counting clicks on links</title>
<script src="jquery.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
var kls=1;
$('<form id="fml" name="fml" method="" action=""><input name="som" type="hidden" value="" /></form>').insertAfter("a:last");
$("a").click(function(event){event.preventDefault();$("input[name='som']").attr("value",kls++);});
onbeforeunload=function(){$.post("teller.php",$("#fml").serializeArray());}
});
</script>
</head>
<body>
<a href="">[1]</a> <a href="">[2]</a> <a href="">[3]</a> <a href="">[4]</a> <a href="">[5]</a>
</body>
</html>
This is the code for teller.php:
<?php
$pointer=fopen("totaal.txt","r+");
$totaal=fgets($pointer);
if(isset($_POST["som"])){$totaal=$totaal+$_POST["som"];}
echo $totaal;
rewind($pointer);
fputs($pointer,$totaal);
fclose($pointer);
?>
The script for counting clicks works on a testing server (xamp) if I don't use iframepage.htm with highslide. From the moment I load iframepage.htm with highslide, the unbeforeunload doesn't seem to work. Could it be that the highslide close button doesn't unload iframepage.htm? Is there an event I can use to unload iframepage.htm from the main page?