1

We have lot of legacy inline javascript code for img onclick , href clicks ets and those clicks starts with javascript:

javascript:showpopup(); 

why do we need javascript: before calling the javascript functions.

any explanation will be appreciated.

asked Dec 4, 2010 at 5:31
1

2 Answers 2

4

The javascript: scheme indicates to the browser that it's JavaScript code and not a relative path from the current page's base URL.

answered Dec 4, 2010 at 5:35
Sign up to request clarification or add additional context in comments.

Comments

2

For inline event handlers like onclick or onmouseover you don't need the javascript: part.

<a href="javascript:you_need_it_here();" onmouseover="but_not_here();">Link</a>

Without javascript: in the href, clicking that link would try to take you to somewhere like this:

http://www.example.com/something/you_need_it_here();

See @Ignacio's answer for the reason.

answered Dec 4, 2010 at 5:44

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.