You need to sign in to do that
Don't have an account?
KMForce
Document Ready and Re-rendering
Hi I need a clarification about when does the jQuery document ready event gets fired. I had a thought that when the document is completely loaded then it gets fired. YES IT IS. But it is also getting fired when you reRender the script which registers document ready event. (Ideally it should not because we are just reRendering not loading the page.) It would be very helpful if someone has any views on it.
Here is the code which gives above stated behaviour.
<apex:page showHeader="true" sidebar="true">
<apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"/>
<apex:form>
<apex:pageBlock>
<apex:pageBlockButtons>
<apex:commandButton value="ReRenderPanel" action="{!null}" reRender="scriptPanel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection id="scriptPanel">
<script>
jQuery(function(){ //document ready
alert('Document is ready');
});
</script>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Here is the code which gives above stated behaviour.
<apex:page showHeader="true" sidebar="true">
<apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"/>
<apex:form>
<apex:pageBlock>
<apex:pageBlockButtons>
<apex:commandButton value="ReRenderPanel" action="{!null}" reRender="scriptPanel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection id="scriptPanel">
<script>
jQuery(function(){ //document ready
alert('Document is ready');
});
</script>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
the script inside it is also getting executed everytime you hit the button..
if you just want it to run only once when the initial document load move the script out of the pageBlockSection.. something like this..
<apex:page showHeader="true" sidebar="true">
<apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"/>
<script>
jQuery(function(){ //document ready
alert('Document is ready');
});
</script>
<apex:form>
<apex:pageBlock>
<apex:pageBlockButtons>
<apex:commandButton value="ReRenderPanel" action="{!null}" reRender="scriptPanel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection id="scriptPanel">
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
With your solution I am good with page, but when I write script inside a component then the component's user has right to reRender the whole component and there I will have no way to stop script from executing again. Let me know if you have any views on it.