this threadで同様の質問があり、非表示のクリックイベントをトリガーする JavaScript 関数がありますcommandLink
。隠しコマンドは、Java Bean でアクションを起動します。このコードは IE では正常に動作しますが、Firefox では動作しません。この問題に関する手がかりはありますか?
JavaScript
<h:outputScript target="head">
HTMLElement.prototype.click = function() {
var evt = this.ownerDocument.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
this.dispatchEvent(evt);
}
function triggerHiddenEvent() {
alert("triggerHiddenEvent is trigger");
document.getElementById("theForm:hiddenCommand").click();
}
</h:outputScript>
XHTML
<h:form id="theForm">
<h:commandLink id="tri_HiddenEvent" value="Trigger Hidden Event" onclick="triggerHiddenEvent"/>
<p style="display:none">
<h:commandLink id="hiddenCommand" styleClass="button" action="#{helloBean.doHiddenCommand}"/>
</p>
...
豆
@ManagedBean
@SessionScoped
public class HelloBean implements Serializable {
public String doHiddenCommand() {
System.out.println("doHiddenCommand is called");
return "";
}
}