cu7co77
Posts: 3
Joined: Thu Apr 14, 2016 7:19 pm

onbeforeunload content in iframe

I use highslide with content in iframe. The page in the iframe contains a script to count clicks on links. The links do not link to other pages, but are used to change content on the same page. The number of clicks are stored in a hidden field. I use $.post() to send form data to the server onbeforeunload. This doesn't seem to work when I use the highslide close button to close the page. I tried to use hs.Expander.prototype.onBeforeClose and onAfterClose instead of onbeforeunload, but that doesn't seem to work either, not even when I added highslide-full.js to the head of the page in the iframe. Is there a simple solution for this? I'm not an expert, so maybe I'm overlooking something. Thank you for your help. I really appreciate highslide
cu7co77
Posts: 3
Joined: Thu Apr 14, 2016 7:19 pm

Re: onbeforeunload content in iframe

Hello, is there anybody?
MisterNeutron
Posts: 440
Joined: Sun Aug 18, 2013 11:20 am

Re: onbeforeunload content in iframe

cu7co77 wrote:Hello, is there anybody?
Probably not. There is virtually no official support for Highslide JS any longer - I think it can be regarded as "abandonware" at this point. I've tried to fill in with some support, but I'm not a Javascript guy, so I can't really help with your problem.
User avatar
KacperMadej
Posts: 4632
Joined: Mon Sep 15, 2014 12:43 pm

Re: onbeforeunload content in iframe

Hi cu7co77,

If you could set up a live example in JSFiddle, then we could check what might be wrong.

Best Regards,
Kacper Madej
Kacper Madej
Highcharts Developer
cu7co77
Posts: 3
Joined: Thu Apr 14, 2016 7:19 pm

Re: onbeforeunload content in iframe

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>&nbsp;<a href="">[2]</a>&nbsp;<a href="">[3]</a>&nbsp;<a href="">[4]</a>&nbsp;<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?

Return to “Highslide JS Usage”