I have created a webpage and I want to organize all my onClick events in a separate JS document, similar to how I handle the rest of the JavaScripts I am using.
The snippets I currently have in the HTML that I would like to modify are:
<a href="http://www.commercial.com" onclick="confirmLeave()" target="_blank">
and
<IMG SRC="picture_small.jpg" alt="Description" onClick="view(this);">
Here is the related JavaScript code that I maintain in a separate document:
function confirmLeave() {
if (confirm("Do you want to leave this page?")) {
return true;
} else {
if (window.event) {
window.event.returnValue = false;
} else {
e.preventDefault();
}
return false;
}
}
And
function view(img) {
imgsrc = img.src.split("_")[0] + "_big.jpg";
viewwin = window.open(imgsrc, 'viewwin', "width=790,height=444,location=0");
viewwin.focus();
}
The first function prompts visitors if they want to leave the page when clicking on a link to an external site, while the second function displays a larger version of the image they clicked on.