JavaScriptã®åããªãã³ã¼ãã(ä¸ç´ç·¨)ãclickã¤ãã³ããå¼·å¶çã«çºçãããããï¼fireEvent/createEventã®ä½¿ãæ¹ï¼
以ä¸ã®JavaScriptã³ã¼ããæå³ããåä½ãããªãã®ã¯ï¼ãªãã§ãããï¼å¶éæéï¼åï¼
ããããäºï¼
- ãã¯ãªãã¯ããã¨ã¡ãã»ã¼ã¸ã表示ãããã¨ããï¼ããã¹ãããã¯ã¹ãããã
- ãã®ããã¹ãããã¯ã¹ã®åä½ãã¹ããããããã¯ãªãã¯ã®ã¤ãã³ããèªåçã«çºçããï¼ã¡ããã¨ã¡ãã»ã¼ã¸ãåºãããã³ã¼ãã§ç¢ºèªããã
<body> ã¤ãã³ãã®çºçæºã¨ãªãããã¹ãããã¯ã¹ï¼ <input type="text" onclick="onclick_func()" id="my_text"> clickæã«ï¼ããã«ã¡ãã»ã¼ã¸ã表示ããã¾ãã <div id="my_div"></div> ãã¹ãï¼ <input type="button" onclick="test_onclick()" value="onclickã®åä½ãã¹ããå®è¡"> <script language="JavaScript"> // clickæã«å¼ã°ããé¢æ° function onclick_func(){ my_div.innerHTML = "ããã¹ãããã¯ã¹ãclickãã¾ããã"; } // clickã®åä½ãã¹ã function test_onclick(){ // clickãã¨ãã¥ã¬ã¼ã my_text.click(); // ãã®çµæï¼ã¡ããã¨æåã表示ããããï¼ if( my_div.innerHTML == "ããã¹ãããã¯ã¹ãclickãã¾ããã" ) { alert("OKã§ãã"); } else { alert("NGã§ãã"); } } </script> </body>
以ä¸ã¯çãã¨è§£èª¬ã
çºçããä¸å ·å
IEã§ã¯ãOKããåºããdivè¦ç´ ã®ä¸ã«ï¼ã¡ãã»ã¼ã¸ã表示ããã¦ããã
ã¯ãªãã¯ã¤ãã³ããã¨ãã¥ã¬ã¼ãã§ãã¦ããã
Firefoxã§ã¯ï¼ãNGããåºããdivè¦ç´ ã®ä¸ã¯ç©ºã®ã¾ã¾ã
ã¯ãªãã¯ã¤ãã³ããæ¬ä¼¼çã«çºç«ã§ãã¦ããªãã
çç±
Firefoxã§ã¯ï¼ããã¹ãããã¯ã¹è¦ç´ ã«click()ã§ããªãã
typeå±æ§ã"button"ã¨ã"submit"ãªãã°èªåã¯ãªãã¯å¯è½ã ãï¼type="text"ã¨ã"file"ã®å ´åã¯ã ãã
How to trigger file input .click() event in Firefox
http://bytes.com/topic/javascript/ans...
Opera and Firefox don't support the click() method for input file elements.
JS Input control .click() does not work under Firefox
http://support.mozilla.com/tiki-view_...
document.getElementById("fpDBox").click();
You can't do that in Firefox.
åé¿ç
対çã¯ï¼ã¤ããã
- æ§å¼ã®æ¹æ³ï¼ã¤ãã³ããã³ãã©ããããããã£ãã¨ãã¦æ±ãæ¹æ³ãï¼ã¤ããé¢æ°ãã»ããã§ããªãã
- ç¾è¡ã®æ¹æ³ï¼DOM Eventãªãã¸ã§ã¯ãã使ãæ¹æ³ãè¤æ°ã®é¢æ°ãã»ããã§ããã
ï¼ï¼ï¼ã¤ãã³ããã³ãã©ããããããã£ãã¨ãã¦æ±ãæ¹æ³
åé ã®ã³ã¼ãã§ã¯ï¼ã¿ã°ã«ç´æ¥onclick=ã®ããã«æ¸ãã¦ããã
ããã¯ï¼HTMLè¦ç´ ã®ãããããã£ãã¨ãã¦ï¼é¢æ°ãä»£å ¥ããæ¹æ³ã
JavaScriptã³ã¼ãã®ä¸ã§ è¦ç´ .onclick=ã ã¨ããã®ãåãã ã
ãã®å ´åï¼ä»£å ¥ãããé¢æ°ã¯åãªãããããã£ã ããï¼ä»£å ¥æã¨åãå½¢å¼ã§å¼ã³åºããã§ããã
// clickãã¨ãã¥ã¬ã¼ã my_text.click(); â // clickãã¨ãã¥ã¬ã¼ã my_text.onclick(); // IE,FFå ±ã«â
ã®ããã«ãããonclickã«ä»£å ¥ããã®ã ããï¼onclickãå¼ã³åºãã°ããï¼ã¨ããã ãã
ãããï¼ããã ã¨ã¤ãã³ããªã¹ããï¼ã¤ããè¨å®ã§ããªãã
ï¼åãªãå±æ§ãªã®ã§ï¼ï¼åç®ã®è¨å®ã§ä¸æ¸ãããã¦ãã¾ããï¼
ã¾ãï¼addEventListenerã¨ãattachEventã§è¨å®ãããã¤ãã³ããªã¹ãã¯ï¼onclick()ã§ã¯å¼ã³åºããªãã
ãªã®ã§ï¼ãã®æ¹æ³ã«ã¯éçãããã
ï¼ï¼ï¼DOM Eventãªãã¸ã§ã¯ãã使ãæ¹æ³
è¤æ°è¨å®ãå¯è½ã«ãªãããã«ã¤ãã³ããã¡ããã¨æ±ãããå ´åï¼Event Objectã使ãã
// clickãã¨ãã¥ã¬ã¼ã my_text.click(); â // clickãã¨ãã¥ã¬ã¼ã var elem = document.getElementById("my_text"); if( /*@cc_on ! @*/ false ) { // IEã®å ´å elem.fireEvent( "onclick" ); } else { // Firefoxã®å ´å var evt = document.createEvent( "MouseEvents" ); // ãã¦ã¹ã¤ãã³ããä½æ evt.initEvent( "click", false, true ); // ã¤ãã³ãã®è©³ç´°ãè¨å® elem.dispatchEvent( evt ); // ã¤ãã³ããå¼·å¶çã«çºçããã }
ãããªãIEã»FFå
±ã«ï¼DOMè¦ç´ ã«ç»é²ããã¦ãããã¹ã¦ã®ã¤ãã³ããªã¹ããå®è¡ããããã¨ãã§ããã
onclick=ã§å±æ§ã¨ãã¦ç»é²ãããé¢æ°ã§ãï¼addEventListnerãªã©ã§ç»é²ãããé¢æ°ã§ãOKã
IEã§ï¼æå®ãããªãã¸ã§ã¯ãã®ç¹å®ã®ã¤ãã³ããå®è¡ãã
http://www.openspc2.org/reibun/JS_Tip...
è¦ç´ .fireEvent( "on" + ã¤ãã³ãå )
Firefoxã§fireEvent
http://tsukamoto.tumblr.com/post/6590...
createEventã使ã
createEventã«æ¸¡ãããã®ã¤ãã³ãã¿ã¤ãä¸è¦§è¡¨
https://developer.mozilla.org/ja/DOM/...
event.initEventã®å¼æ°ã«ã¤ãã¦èª¬æ
https://developer.mozilla.org/ja/DOM:...
ãã¼ãã¼ãã¤ãã³ãã®å ´å
clickãmousedownã®ãããªãã¦ã¹ç³»ã®ã¤ãã³ãã ãã§ãªãï¼ãã¼æ¼ä¸ã®ã¤ãã³ããçºç«ã§ããã
ä¸è¨ã®é¢æ°ãåç
§ã
// elem : ãã¼æ¼ä¸ã¤ãã³ããçºçããããè¦ç´ // key_code : æ¼ä¸ãããã¼ã®ãã¼ã³ã¼ãã"right"ã®ãããªæååæå®ãå¯ function fire_key_down_event( elem, key_code ) { // ãã¼ã³ã¼ããèª¿æ´ if( key_code == "left" ){ key_code = 37; } else if( key_code == "right" ){ key_code = 39; } else if( key_code == "up" ){ key_code = 38; } else if( key_code == "down" ){ key_code = 40; } // ã¤ãã³ããçºç«ããã if( /*@cc_on ! @*/ false ) { // IEã®å ´å var evt = document.createEventObject(); evt.keyCode = key_code; elem.fireEvent( "onkeydown", evt ); } else { // Firefoxã®å ´å var evt = document.createEvent("KeyboardEvent"); evt.initKeyEvent("keydown", true, true, null, false, false, false, false, key_code, 0 ); elem.dispatchEvent( evt ); } }
ãã¼ã¤ãã³ããæ¬ä¼¼çã«çºçããããã¨ã¯å¯è½ï¼
http://questionbox.jp.msn.com/qa46737...
event.initKeyEventã®å¼æ°
https://developer.mozilla.org/en/DOM/...
document.createEventObject()ã¨ã¯
http://javascript.gakaa.com/document-...
IEã§ï¼fireEvent()ã«æ¸¡ãããã®ã¤ãã³ããªãã¸ã§ã¯ããä½æãã
è£è¶³
ãããã®æ å ±ã¯ï¼è¤éãªUIã®Webãã¼ã¸ããã¹ãé§åã§éçºããããã«ã¯å¿ é ã¨ãããã
ãªãï¼ãã®å帰ãã¹ããã¼ã«ã®Seleniumã§ãï¼ãã¡ããå©ç¨ããã¦ããã
Seleniumã®ã³ã¢ã§ããselenium-browserbot.jsã®ï¼214è¡ç®ãè¦ã¦ã¿ããã
203 /* Fire a mouse event in a browser-compatible manner */ ã»ã»ã» 214 if (element.fireEvent) { ã»ã»ã» 246 else { var evt = document.createEvent('MouseEvents'); if (evt.initMouseEvent)
ã¨ãã£ãå ·åã«ï¼ãã¦ã¹ã¤ãã³ããçºçãããããã«ï¼ãã®ã¨ã³ããªã¼ã§åãä¸ããã®ã¨åãããã«ãã©ã¦ã¶ãã¨ã«ç°ãªã£ãé¢æ°ãå¼ã³åºãã¦ããã®ããããã
ã»ãã®åèURLï¼
prototype.jsã®Event.fire()ã«ãã¤ãã£ãã¤ãã³ãã対å¿ããã
http://rakuto.blogspot.com/2008/01/ja...Script.aculo.usã«åå¨ããã¤ãã³ãçºç«ç¨é¢æ°ï¼Firefoxå°ç¨ï¼
http://gihyo.jp/dev/feature/01/script...prototype.js ã®ã¤ãã³ãã»ããªã¬ã¼
http://hwat.sakura.ne.jp/hpod/200611/...
é¢é£ããè¨äºï¼
JavaScriptã®åããªãã³ã¼ãã(ä¸ç´ç·¨)ãä¸è¦ãªã¤ãã³ããé£éã§çºçãã¦ãã¾ãããï¼ãããªã³ã°ã®å¯¾å¦ï¼
http://language-and-engineering.hatenablog.jp/entry/20081128/1227843561
JavaScriptã®åããªãã³ã¼ãã(ä¸ç´ç·¨)ãsetTimeoutã®ã¿ã¤ãã¼ãæå®æå»ã«åããªãã¨ã©ã¼ãï¼JavaScriptããã«ãã¹ã¬ããã ã¨ãã誤解ï¼
http://language-and-engineering.hatenablog.jp/entry/20090614/p1
JavaScriptã®åããªãã³ã¼ãã(ä¸ç´ç·¨)ãåç追å ããã¤ãã³ãã®å®è¡é åº ( addEventListener vs attachEvent )
http://language-and-engineering.hatenablog.jp/entry/20081011/1223680300
JavaScriptã®åããªãã³ã¼ãã(ä¸ç´ç·¨)ãã¤ãã³ãå¼·å¶çºçã¾ã§ã®é
延æéããªãããã
http://language-and-engineering.hatenablog.jp/entry/20090909/p1