1

Hy guys and hope you can help.

I have a very simple jQuery hide function that was working but some bugInTheRom has occured overnight and it no longer does. Effectively I'm trying to add a 'Patience' warning visible whilst some SWF loads.

Here's my call in the <head> section...

<script type="text/javascript" src="js/jquery-1.6.1.js"></script>
<script type="text/javascript">
function hidden() {
    $('.patience').hide();
};
window.onload=hidden;
</script>

and here's the class it affects...

<p class="patience">Please be patient, the interactive book below and the PDF links may take a while to fully load.</p>

and the associated CSS...

.patience {
    visibility: visible;
    background-color: #CCC;
    border: 1px solid #000;
    margin-right: 10px;
    margin-left: 10px;
}

Any ideas why it doesn't hide once the whole of the SWF has been loaded?

My thanks. R

1
  • does it not hide at all, or does it hide too early? Commented Jun 28, 2011 at 17:09

5 Answers 5

3

If you're having problems, I would switch to:

$(document).ready(function () {
    $(window).load(function () {
        $('.patience').hide();
    });
});

which might help everything initialize properly.

I'm not sure I understand how the SWF is related... perhaps you meant to say swf_elem.onload or something instead of window.onload?

Sign up to request clarification or add additional context in comments.

2 Comments

@Rog did you test this one? It's the cleanest answer, and also considers that there may be some other event being fired by the SWF loader.
Thanks both to @Mu Mind and @Alnitak, I tried this and, sadly, it didn't work. It's live here, rogw.net/lulworth . @Alnitak, thanks for your perserverence, I'll hunt out a JS debugger.
1

For one thing change window.onload=hidden; to $(function(){hidden();});

The new way i suggested is using jQuery's version of document ready which makes sure that the elements that you might want to affect are loaded and can be used.

Also i see nothing in your code which connects this hidden() function to any SWF load

See Fiddle: http://jsfiddle.net/maniator/XX8ym/

19 Comments

Wouldn't $(hidden); be more efficient?
@Ender, that is under the assumption that the OP does not want to do anything else on startup, yes.
Thanks Neal, I deliberately skipped including all the |SWF load stuff, I'll experiment with your new function call and come back.
From the Mozilla docs: The load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images and sub-frames have finished loading. Basically, this means that onload is called when the DOM is loaded, but not necessarily when a plugin is loaded. As @Neal mentioned, you need to see if flash will raise an event once loaded and bind to that.
Also, something I just noticed - OP is trying to run his function on page load, whereas our suggestions would execute the function on DOM ready. Minor difference, but could be important.
|
1

Firstly - window.onload is the right place to put this handler - unlike $(document).ready() it will wait until all sub-frames, images, etc, have loaded.

What I don't know is whether window.onload will also wait for an SWF object to be loaded.

If it doesn't wait for the SWF, then the effect would be that your .patience div will disappear too early, since the rest of the page will have finished loaded.

It it does wait, but your div isn't disappearing at all, this suggests that you've simply got a trivial error somewhere in your real JS code that is preventing the .hide() from ever being called.

Since you've said that the div isn't disappearing, I would suggest that you've got the latter problem, in which case a few minutes with a JS debugger should reveal (no pun intended) the problem.

Comments

0

May be your jQuery failed to load. Also, when using jQuery, use jQuery's $.ready instead of window.onload to ensure all things are in peace before trying to do anything!

Comments

0

My stupid mistake!

Nothing wrong with the code I showed you but I discovered that I was calling <script type="text/javascript" src="js/jquery-1.6.1.js"></script>in the head and only the "js/jquery-1.6.1.min.js" script existed on my server.

Feel stupid now but thanks all who contributed.

Cheers Rog

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.