www.webdeveloper.com
Results 1 to 1 of 1

Thread: How to retrieve errors of Javascript?

  1. #1
    Join Date
    Jan 2013
    Posts
    84

    Question How to retrieve errors of Javascript?

    Hi, there are a method that can report an error accured when a JS script is executed?

    For exemple, following the Javascript: Complete Guide book, i've tryed this snippet for make practice:

    PHP Code:
    whenReady(function() 
               {
                  var 
    clock document.getElementById("clock"); // The clock element
                  
    var icon = new Image(); // An image to drag
                  
    icon.src "clock-icon.png"// Image URL
                  
                  // Display the time once every minute
                  
    function displayTime() 
                  { 
    alert('lol')
                      var 
    now = new Date(); // Get current time
                      
    var hrs now.getHours(), 
                      
    mins now.getMinutes();
                      
                      if (
    mins 10mins "0" mins;
                      
    clock.innerHTML hrs ":" mins// Display current time
                      
    setTimeout(displayTime60000); // Run again in 1 minute
                  
    }
                  
                  
    displayTime();
                  
    // Make the clock draggable
                  // We can also do this with an HTML attribute: <span draggable="true">...
                  
    clock.draggable true;
                  
    // Set up drag event handlers
                  
    clock.ondragstart = function(event
                  {
                      var 
    event event || window.event// For IE compatability
                      // The dataTransfer property is key to the drag-and-drop API
                      
    var dt event.dataTransfer;
        
                      
    // Tell the browser what is being dragged.
                      // The Date() constructor used as a function returns a timestamp string
                      
    dt.setData("Text"Date() + "\n");
                      
    // Tell the browser to drag our icon to represent the timestamp, in
                      // browsers that support that. Without this line, the browser may
                      // use an image of the clock text as the value to drag.
                      
    if (dt.setDragImagedt.setDragImage(icon00);
                  };
               });

    </script>


    <style>
    #clock { /* Make the clock look nice */
    font: bold 24pt sans; background: #ddf; padding: 10px;
    border: solid black 2px; border-radius: 10px;
    }
    </style>


    <h1>Drag timestamps from the clock</h1>

    <span id="clock"></span> <!-- The time is displayed here -->
    <textarea cols=60 rows=20></textarea> <!-- You can drop timestamps here --> 
    (it's not necessary to read the code)
    The problem that i had was that the code was executed once opened the page, while the document was not fully loaded and "clock" object doesn't exist... So it didn't work
    After i've understand that i should insert a script that launch the function once the document is ready! This means that without this function, i get into an error such "the object doesn't exist" (or something of genre), but how keep trace of it?
    Last edited by American horizo; 03-22-2013 at 01:46 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles