Custom Javascript
-
I said
assuming you have a function onLoad that does the stuff you want done on page load
Which means that you should define the function like this:
function onLoad() { console.log('yeah it works'); }
-
@jenkler said in Custom Javascript:
$(document).ready(onLoad);
$(window).on('action:ajaxify.end', onLoad);So, someting like this?
function onLoad() {
console.log('yeah it works');
}$(document).ready(onLoad);
$(window).on('action:ajaxify.end', onLoad); -
@jenkler yes it should work. Have you tried it?
-
Yes, it seams to work. Could i do this in a widget
$(document).ready(onLoad);
$(window).on('action:ajaxify.end', onLoad);So i only load it from that page! I guess that would be the right way to go!
-
I get onLoad is not defined if I put that in a widget. Thats because custom javascript render last.
-
You should just put the onLoad function in the widget code with the other two things.
-
Also, you might get an error if you access the page with the widget on cold load. If that does happen, then you'll need to add a window onload event handler with addEventListener and put that stuff inside it.
-
<script>
function onLoad() {
alert('yeah it works');
}$(document).ready(onLoad);
$(window).on('action:ajaxify.end', onLoad);
</script>Tried to add this into a widget. Cold load does not work and i get double alerts and it follows on other pages.
-
I realise that things are difficult but please try to tinker around with things. I try to help everybody but I'm not gonna do everything for you. If I do, you'll never learn anything.
-
ok, thanks. I will see if I can get it to work.
-
I got it to work with
$(window).on('action:ajaxify.end', onLoad);
for the global stuff and made a script that would wait for jquery to be loaded