Should I add javascript: before the html tag function?

Possible duplicate:
When do I need to specify the JavaScript protocol?

eg

 <body onload="javascript:something();">

      

in this code, should I put javascript:

?

some of the attatch codes javascript:

,

but some don't.

what is safe and correct?

+2


source to share


3 answers


A better solution would be to avoid using JavaScript explicitly in your markup altogether and use something like jQuery to extract everything into a separate file; you can do something like this:



$(function()
{
    // This will be run when the document is loaded.
    alert('foo');

    $('#some-link').click(function()
    {
        // This will be run when the element with id `some-link` is clicked.
        alert('bar');
    });
});

      

+3


source


No. Just use your javascript.

<body onload="something();">

      

javascript:

can be used with an attribute of an href

element a

.



<a href="javascript:something();">

      

But for the protocol, I prefer to use the method onload

.

+3


source


I would suggest something like

<body>
...
<script>
function something() {}
window.onload = something;
</script>

      

+1


source







All Articles