[Solved] how to use jQuery on multiple pages


Right… I had found the downvotes strange… you guys almost gave me a sad birthday 😛 turns out the issue wasn’t understandable till you fall in the trap. Found the solution in one of these obscure web places 😉

Here you go:
Somehow pages loaded into other pages through certain methods (ajax being one?) get stripped of their “calling the javascript” capabilities. I had:

main page –> | div 1 on left | div 2 on right|

Stuff gets loaded into div 2 depending on actions taken on div 1 or div 2 itself. This means in my case that whatever is loaded into div 2 ALSO needs javascript capabilities for the decision taking.

a random page X.htm—> |html+css+js|

(this one being one of various “pages” that could be loaded in DIV 2 in main page)

html works ok, css works ok, js doesn’t work AT ALL, never ever. Not even SEEN by anyone? Dunno why…

SOLUTION:

1) put the JS relevant to your child pages in of main page!
2) put the following at end of any page loaded into DIV 2, like “page X” above

<img src="https://stackoverflow.com/questions/31361737/oneTransparentPixel.png" onload="theFunctionWeNeedInPageX()" />

Where you create a 1 pixel transparent image to be loaded (!). The hack here is that the loading of the image allows for the calling of the function we need…

I don’t know if the JS code is unseen if in the child page, or not executed, or the page isn’t yet ready to execute it. Whatever the case, this “solution” allows for
1) code is now seen
2) it is executed once the page is ready to let the function do the stuff it should. In my case the function stylizes the mouse over/collapsing/etc of a list in the child page X. So it might have been that the code was not yet ready to be applied on the list because the list didn’t yet exist – was not rendered by the browser, or because the code was not being seen by anyone. Could someone clarify what was happening, or point us to what to read so we know?
Thank you for your time 🙂

solved how to use jQuery on multiple pages