Skip to content
Advertisement

a href=javascript:function() in firefox not working

I tried using a href=javascript:function() in a button, with a function to execute it. It works in Chrome but it doesn’t work in Firefox.

Firefox doesn’t alert and open blank tab.

Anyone can help me?

<script>
function verifyisbot() {
alert("test."); 
var win = window.open("http://yahoo.com", '_blank');
win.focus();
}
</script>

Below is button code

<div class="frb_textcenter">
<a  target="_blank" class="frb_button frb_round  frb_center frb_fullwidth" href="Javascript:verifyisbot();">
click here
</a>
</div>

Update

I should have added that im using a live editor(profitbuilder) in wordpress to generate the page and button. There is no area for me to insert additional javascript onclick function to the button. So i figure out to use “ahref” blank field in the live editor to input javascript call function to fire up the function.

Is there any way i can make this work through the ahref without using onclick event? Or can i specify onclick function in the ahref field?

Sorry the test() is actually verifybot() function, typo mistake

Advertisement

Answer

Give serious consideration to separating your JavaScript and your HTML such that the problem goes away. For instance, add an ID to your anchor and add an event handler through script:

<div class="frb_textcenter">
  <a id="verify" target="_blank" class="frb_button frb_round  frb_center frb_fullwidth" href="http://yahoo.com">
    click here
  </a>
</div>

Later…

<script>
function test() {
  alert("test."); 
  var win = window.open("http://yahoo.com", '_blank');
  win.focus();
}
window.onload = function () { 
  document.getElementById('verify').addEventListener('click', test); 
};
</script>

Do note that with the example provided, you don’t actually need JavaScript at all. The HTML itself will cause a new window/tab to open with Yahoo! loaded…

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement