Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Cant get body onload to fire

  • 27-02-2009 10:31am
    #1
    Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭


    Hi,

    I have some simple JS that I cant get to fire on my ASP.net Masterpage.

    It's the same for FF3 and IE7, havent checked in other browsers yet.

    There are no JS errors, just nothing is happening...
    <script type="text/javascript">
        function showTerms() {
          alert("got here");
          var termsContainerID = '';
    
          if ($get('hdnShowTerms') != null)
            termsContainerID = $get('hdnShowTerms').value;
            
          if ($get(termsContainerID) != null) {
            $.modal(document.getElementById(termsContainerID), { overlayId: ('TermsModal-overlay'), containerId: ('TermsModal-container') });
          }
          
        }
      </script>
    </head>
    
      <body onload="showTerms();" >
    

    Anyone see anything wrong with this? :confused:


Comments

  • Registered Users, Registered Users 2 Posts: 4,475 ✭✭✭corblimey


    Works fine as is in my FF3 and IE7 although I did have to allow ActiveX content on IE7 before it worked. Could your security settings be stopping it?
    <html>
    <head>
    <script type="text/javascript">
        function showTerms() {
          alert("got here");
          var termsContainerID = '';
    
          if ($get('hdnShowTerms') != null)
            termsContainerID = $get('hdnShowTerms').value;
            
          if ($get(termsContainerID) != null) {
            $.modal(document.getElementById(termsContainerID), { overlayId: ('TermsModal-overlay'), containerId: ('TermsModal-container') });
          }
          
        }
      </script>
    </head>
    
      <body onload="showTerms();" >
    hello
    </body>
    </html>
    

    (ETA: I get the "got here" alert, obviously nothing else works)


  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    Works on FF and IE for me as well.


  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭John_Mc


    Thanks lads, been trying to the past two days to get a JS function onto a page should a server side function decide that on needs to be added. I used the ClientScript Startup method which worked in FF, but caused an "operation aborted" error in IE :(

    I've had to go about things in a completely different way now and it's working. Still dont know why the onload method wasnt called though...


  • Closed Accounts Posts: 2,300 ✭✭✭nice1franko


    AFAIR, the body onload event is a bit flaky (may not fire if any dom elements in it are edited before the event would naturally fire or something)... try document.onload instead.


  • Moderators, Science, Health & Environment Moderators Posts: 9,035 Mod ✭✭✭✭mewso


    Since we are now in 2009 I thought I would make a few suggestions.

    1. Stop using inline javascript in html.
    2. Put your script in external js files.
    3. Write your script to be unobtrusive.
    4. Use a proper well documented method to add load events to your page like the addLoadEvent function or putting your script link at the end of the body content.
    5. Please stop using inline javascript in html.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,120 ✭✭✭p


    I'd echo wat musician has said.

    Put the onload event in the javascript, not the HTML and you'll be writing much better practice JS.

    http://onlinetools.org/articles/unobtrusivejavascript/chapter4.html


Advertisement