PDA

View Full Version : Dynamic jQuery loading, why script is executed 2 times?



fallen
05-22-2012, 12:08 PM
Hi,

I am making a widget to work on any site, that means not my site, so I have no control of what other libraries are used on the page.
Thats why I am loading my own jQuery libraries dynamically and then execute my own code.

An issue I have that some sites are loading fine and all is working as expected, but some sites are executing the code 2 times.

I have made a page dump and put on my own server, so I can replicate the issue better.

GOOD: here is a page that works OK: (see the button that says: send these contact details and map to your mobile.)

http://test.plustest.info/suffolk/contact.html

BAD: here is the page that shows the button I am trying to load 2 times:

http://test.plustest.info/cream.html

As you can see the button appears 2 times, which is wrong...
Even it shows 2 times, the popup appears just ok when you click on the button.

Would anyone be able to check what can be wrong here?
the code is in the:
<div id="now_send_it_wrapper"> so its easier to find.

Any help would be much appreciated.

Thanks,
Vladas

hdewantara
05-23-2012, 02:24 PM
Maybe because the script is a child of (within) the target div it is trying to modify:

<div id="now_send_it_wrapper">
<script src="http://beta.nowsend.it/get/button/81" type="text/javascript"></script>
</div>

Try separate them as siblings, like below:

<div id="now_send_it_wrapper"></div>
<script src="http://beta.nowsend.it/get/button/81" type="text/javascript"></script>

fallen
05-23-2012, 03:06 PM
Hi,

tried that, but it looks ok on the other examples, it is just that one site I am having such issues. Not sure if it is because the other libraries doing something weird as other sites are all fine...

Cheers,
Vladas