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 < 10) mins = "0" + mins;
clock.innerHTML = hrs + ":" + mins; // Display current time
setTimeout(displayTime, 60000); // 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.setDragImage) dt.setDragImage(icon, 0, 0);
};
});
</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?
Bookmarks