views:

178

answers:

3

I'm using shadowbox for some html/iframe links, which effectively opens up the page in a lightbox. Everything works great - except when someone clicks before the javascript is done loading.

Now, the obvious answer is to not use links as the targets of loading the shadowbox. But this poses usability problems if javascript is disabled. Does anyone have any ideas on how else to solve the problem? I'm considering loading javascript inline that would deactivate the links until the page is done loading, although I'm not exactly sure how I'd approach that.

All ideas are welcome!

+2  A: 

In general, I'd consider this to be a non-issue, but can't you just call the shadowbox processor inline directly after the links?

i.e.:

.link, .link, .link script $(".link").shadowbox(); /script

Tegeril
+1 I agree he is doing it correctly and any solution to minimize the delay is going to be detrimental to usability.
Josh Stodola
Yeah, I certainly don't advise that you put the code inline. What should be done instead is a broad analysis of what is keeping the DOM from loading fast enough.
Tegeril
I disagree that this is always unnecessary. It may take time to load simply because there's a lot to load. Look at GMail. Do you think the user experience would be improved by removing the loading screen?
Annabelle
Not at all, but this person isn't using a loading screen. If it were appropriate for his implementation that would be an acceptable solution too.
Tegeril
A: 

You can disable all links in a page using jQuery (a great minimalistic javascript framework)

<script type="text/javascript">
    $(function() {
        $('a').click(function(event) {
            event.preventDefault();
            return false;
        });
    });
</script>
Moropo
This missed the point entirely. That effect would suffer the same delay as his shadowbox process delay as they are both going to wait for the DOM to finish loading.
Tegeril
A: 

You could define your links as

<a id="myLink" href="#" onclick="return false">...</a>

and then reassign the click event handler once your javascript is loaded. Or, if your links have non-JavaScript alternatives:

<a id="myLink" href="/path/to/nonJS/alternative.html">...</a>

Again, when your JavaScript loads you can add a click event handler and override the default action.

If it takes a while for all of your scripts to load, you might reconsider if you need to load all of them right away. If you do, then you could implement a loading screen (below example uses jQuery, but it doesn't have to):

<div id="loading">
    Loading...
</div>
<div id="content" style="display: none;">
  // Site content...
</div>
// Load your scripts here...
<script type="text/javascript" src="..."></script>
<script type="text/javascript">
  $(document).ready(function() {
    $('#loading').hide();
    $('#content').show();
  });
</script>

This way your site content isn't visible until all of your scripts are loaded.

Annabelle
Link is worthless to people with Javascript disabled.
Josh Stodola
I assumed from the post that JavaScript is required for the site. I added an alternate link syntax that works without JS.
Annabelle