1

At the window.onload() event of a standard object detail page I am storing the time value in one of its fields. I have embedded a vf page along with this detail page. At the click of a button in the embedded vf page shown,the object detail page refreshes and the window.onload event resets the value to the new time stored in the object field. Is there a way to stop the detail page from refreshing?

Just adding snippets of the code here :

<script>
    window.onload = function() 
    {
        sforce.connection.sessionId = "{!$Api.Session_ID}";
        var aResult = sforce.connection.query("SELECT Time__c FROM card__c where Id = {!card__c.Id}");
        /*code to update the time filed on the object*/
</script>
<script>
    function abc()  
    {
        /*Some DML Operations here*/
    }
</script>
    <apex:form>
        <apex:pageBlock>
           <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Do Something" onclick="abc" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>  
</apex:page>
  • Can you show us your code please ? – SF_user Sep 5 '14 at 11:56
  • Hi I have added a little bit of the code to give you an idea of what I am trying to do. Whenever I click the do something button the object detail page refreshes. The onload function in the script works perfectly. – Astha Sharma Sep 5 '14 at 12:11
4

You need to add return false; to your onclick function. Without that the page will reload after clicking.

Another solution is to add an rerender="none" tparameter to the command button.

So it will look like this:

<apex:commandButton value="Do Something" onclick="abc(); return false;" />

or like this:

<apex:commandButton value="Do Something" onclick="abc(); reRender="none" />
1

Change :

<apex:commandButton value="Do Something" onclick="abc()" />

to :

<apex:commandButton value="Do Something" onclick="abc(); return false;" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.