一个href = javascript:firefox中的function()工作不正常

时间:2016-08-09 17:16:24

标签: javascript html firefox

我尝试在按钮中使用a href=javascript:function(),并使用函数执行它。它适用于Chrome,但在Firefox中不起作用。

Firefox不会提醒并打开空白标签。

任何人都可以帮助我吗?

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

以下是按钮代码

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

更新

我应该在wordpress中使用实时编辑器(profitbuilder)来生成页面和按钮。我没有区域可以在按钮上插入额外的javascript onclick功能。所以我想在实时编辑器中使用“ahref”空白字段输入javascript调用函数来启动函数。

有没有办法在不使用onclick事件的情况下通过ahref实现这项工作?或者我可以在ahref字段中指定onclick函数吗?

抱歉test()实际上是verifybot()函数,错字错误

3 个答案:

答案 0 :(得分:2)

使用onclick事件代替a href=javascript。它适用于firefox。请参阅下文:

<div class="frb_textcenter">
<a target="_blank" class="frb_button frb_round  frb_center frb_fullwidth" onclick="test()">click here</a></div>

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

更新1 :您可以在不使用javascript的情况下执行此操作。您只需在href属性中添加链接。请参阅以下内容:

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

答案 1 :(得分:2)

您只能使用public class Thing { private UnaryOperator<Float> func; public Thing() { func = x -> 2 * x; } public float F(float x) { return func.apply(x); } } 属性

来实现目标
href

它有效,因为当浏览器跟随<a href="javascript:void(verifyisbot())" class="frb_button frb_round frb_center frb_fullwidth"> click here </a> URI时,它会评估URI中的代码,然后用返回的值替换页面内容,除非返回的值为javascript:undefined运算符可用于返回void

答案 2 :(得分:0)

请认真考虑将JavaScript和HTML分开,以免问题消失。例如,向锚点添加ID并通过脚本添加事件处理程序:

<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>

...后来

<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>

请注意,根据提供的示例,您根本不需要JavaScript。 HTML本身将导致使用Yahoo!打开一个新窗口/选项卡加载...

相关问题