SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Body onload javascript doesnt fire with thickbox

    Hi ,

    I have a javascript that needs to be executed on page load.
    It doesnt work if i call the thickbox from a link. But if i run the thickbox(the asp page) on its own, the onload event works.

    So I believe it is due to the onload event not fired if the page is called via a URL.

    Something must have been interefering with the JS.

    Can someone help.

    This is how i call the js.

    HTML Code:
    <body onload="javascript:listboxload();">
    Thanks

  2. #2
    SitePoint Zealot
    Join Date
    Oct 2004
    Location
    Sydney, Australia
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since thickbox is a plugin for jQuery, you could use the following instead.

    Code:
    <script type="text/javascript">
    $(document).ready(function() {
    listboxload();
    });
    </script>
    http://docs.jquery.com/Events/ready
    Last edited by Bling; Feb 21, 2008 at 20:18. Reason: fixed code

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by blackwidow_81 View Post
    Something must have been interefering with the JS.
    Can someone help.
    This is how i call the js.

    HTML Code:
    <body onload="javascript:listboxload();">
    I think that a really big hammer is needed to say this but, "Do not use the javascript pseudo protocol".

    Pardon me now, but it's long past time for a rant about the javascript pseudo protocol.

    It was designed to show the contents as a new page, in much the same way as the http protocol.
    Code html4strict:
    <a href="javascript:<p>Thank you for the submission.</p>" onclick="submitForm()">Submit Form</a>

    If there was no understandable contents it didn't show a blank page, it just left the page as it was and interpreted it as javascript instead. The javascript handler was also poorly used to provide a link that did nothing, to hold an event handler of some kind.

    Code html4strict:
    <a href="javascript:void(0)" onclick="doSomething()">Do something</a>

    There are amazingly better ways to perform this task. if you're still using inline event handlers it can be done like this:

    Code html4strict:
    <a href="page.html" onclick="return doSomething()">Do something</a>

    where the doSomething() function can return false to cancel the default behaviour, that of following the link.

    If you're using traditional event registration, you should do it like this:

    Code html4strict:
    <a id="myLink" href="page.html">Do something</a>

    Code javascript:
    document.getElementById('myLink').onclick = doSomething;

    When the javascript pseudo protocol is used now, there are some Web browsers that throw up security warnings about it. So please, stop using the javascript pseudo protocol technique. It was never desired to be used for scripting. Netscape 2 was the first javascript capable browser from Netscape, and even that one supports the inline event handler techniques.

    So in summary, please do not use the javascript pseudo protocol.

    Now, *deep breath*, please change your code to at least the following

    Code html4strict:
    <body onload="listboxload();">

    or as Bling suggested, use the library supported function instead.
    Last edited by paul_wilkins; Feb 22, 2008 at 01:10.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •