3

I have an anchor that triggers a javascript which uses jquery:

<a href="javascript: $('#dash-main').load('billing.php')">text</a>

This anchor works fine in Chrome, and even in IE, but when I use it in FF, the browsers redirects to "http://javascript: $('#dash-main').load('billing.php')".

Any idea what is wrong?

4
  • Consider connecting this to a function instead that calls it. Aug 4, 2012 at 15:46
  • Remember to accept and answer to get that accept rate up. Aug 4, 2012 at 20:58
  • Can you link to an example? This is quite odd and unexpected behavior. Aug 5, 2012 at 5:41
  • Don't use javascript: HREFs. Use the cross-browser onclick event.
    – user229044
    Aug 10, 2012 at 2:28

3 Answers 3

10

Use onclick and avoid the problem:

<a href="#" onclick="$('#dash-main').load('billing.php');return false;">text</a>
2
  • 1
    href="javascript: is really ugly in the status bar. Make sure you return false; in the onclick or the page will jump. Aug 4, 2012 at 15:49
  • 1
    Use href="javascript:void(0);" instead of href="#" - this avoids needing to return false at the end of onclick. void(0) is basically a no-op for javascript. In the href attribute, it keeps it from jumping to the top of the page or navigating away, regardless of what onclick does or does not return.
    – Mar
    Oct 12, 2015 at 21:43
4

Why not use:

<a href="#" onclick="$('#dash-main').load('billing.php')">text</a>

Cross-browser compatible!

0
-3

Did you try returning false?

<a href="javascript: $('#dash-main').load('billing.php'); return false;">text</a>
1
  • What about just putting an ";" at the end of your statement? Aug 4, 2012 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.