Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have a small script that customises certain list views, hiding buttons.

This is done using jQuery $(document).ready()

Because this js is manipulating standard pages it is stored in the left sidebar.

However, I can see that the call to the function is being made when the document is not really ready. I'm guessing that salesforce is fetching list contents (including buttons) dynamically.

So my attempts to show or hide something are in vain because that thing has not yet been inserted into the page.

How can I make sure that this script get executed when salesforce is done rendering the list completely?

share|improve this question
1  
What list are your referring to exactly? Can you provide more specific details and maybe some sample code? –  fehays Aug 6 at 15:19
    
It's the standard list view page (aka one of the search layouts) for a custom object. –  powlo Aug 7 at 16:04

1 Answer 1

up vote 4 down vote accepted

Presumably you are aware that Salesforce is making this sort of code harder to add - see End of javascript sidebar hacks?.

If you can detect (e.g. by the presence of an element of a certain class) when the rendering is done, then you can poll for that using JavaScript's setTimeout:

function checkIfThere() {
    // Check for the element and do whatever you need to if you find it
    var foundIt = ...;
    if (!foundIt) {
        // Do the check again in 500 ms
        setTimeout(checkIfThere, 500);
    } else {
        // All done
    }
}
// Call directly to start it
checkIfThere();
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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