NetTalk Central

Author Topic: Browse NetSource child js refresh  (Read 3690 times)

Alberto

  • Hero Member
  • *****
  • Posts: 1873
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Browse NetSource child js refresh
« on: October 03, 2017, 01:03:06 PM »
Hi,
Memory form which has a Browse wich has a Source child
That source shows an image related to the browse and runs a script to draw some other images over.
First time it runs ok but when I click on another browse row only the image change, its like the js script is not run.
Do I have to run it in some place in the browse when changing a row?
Any ideas?
Thanks

PD:this is the code of the source, it changes every time the image changes and this is done ok:

Code: [Select]
<div id="imagemarkchild_bimages_div"  class="adiv">
<table cellspacing="0" cellpadding="0" border="0" style="width: 100%; min-width: 320px;">
<tr>
<td style="padding: 10px; width: 80%">
<div align="center">
<img  id="image" src="/uploads/00000001/00000015.jpg                         " width="100%" /><br/>
</div>
</td>
</tr>
</table>
<script type="text/javascript">
;(function($) {
var notes = [
     {x: "0.443185704514364", y:"0.804175850125945", note:"", img:"red"},
     {x: "0.549888850889193", y:"0.802916404282116", note:"", img:"rcir"},
     {x: "0.510217168262654", y:"0.830624212846348", note:"", img:"gcir"},
     {x: "0.329642612859097", y:"0.83818088790932", note:"15555555555555555555", img:"acir"},
     {x: "0.274923050615595", y:"0.466644363979849", note:"verdeeeeeeeeeeeeee", img:"green"},
     {x: "0.322964123006834", y:"0.112427783613445", note:"", img:"blue"},
     {x: "0.660093963553531", y:"0.337217699579832", note:"", img:"acir"},
     {x: "0.568977790432802", y:"0.339318539915966", note:"", img:"blue"}                     ];
$(window).load(function() {
var $img = $("#image").imgNotes({
});
$img.imgNotes("import", notes);
});
})(jQuery);
</script>
</div><!-- imagemarkchild_bimages -->
« Last Edit: October 03, 2017, 01:32:40 PM by michelis »
-----------
Regards
Alberto

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Browse NetSource child js refresh
« Reply #1 on: October 03, 2017, 09:15:36 PM »
Hi Alberto,

So yes, this is in the nature of how the web page (the "DOM") and JavaScript work together.

If you have a child of the browse, then that child is "some HTML". That HTML is placed "on the window" and then you run JavaScript on that HTML.

If another row in the browse is clicked, then the child HTML is "removed" from the DOM. Poof, it's gone. Then another block of HTML arrives. This is "the same" as the earlier one (since it came from the same NetWebSource) but as far as the browser is concerned this is _all new code_.

Therefore the JavaScript has to be called again to "run on this new HTML".
Typically you can do this by adding p_web.Script calls to the NetWebSource so everything there is self-contained.

It will need to be in the p_web.Script call because then it will _run_ on the update call. The current code you have in <script> won't run because that only runs when the _page_ is opened. Since this is an Ajax update it won't run.
but adding it to the p_web.Script instead of in the code as <script> will make it run.

cheers
Bruce