これは単純なシナリオです。クリック イベントは Firefox では正常に機能しますが、IE では機能しません。詳細に行きましょう。以下のようなボタンがあります。
<h:form id="theForm">
<h:commandLink id="theButton" styleClass="button" action="#{theBean.doWork}"/>
</h:form>
次のようにJavaScriptからボタンのクリックイベントを呼び出そうとすると:
document.getElementById('theForm:theButton').click();
このスレッドによると、以下のコードを次のように配置する必要があります。
<script language="javascript" type="text/javascript">
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);
}
しかし、JavaScript でこのコードを使用すると、Firefox では実際に機能しますが、IE では機能しなくなります。IE と Firefox の両方で動作させる方法を教えてください。