maniootek Posted February 21, 2017 Share Posted February 21, 2017 I have html file with source code: <script> function highlight_row() { var table = document.getElementById('mytable'); var cells = table.getElementsByTagName('td'); for (var i = 0; i < cells.length; i++) { var cell = cells[i]; cell.onclick = function () { var rowId = this.parentNode.rowIndex; var rowsNotSelected = table.getElementsByTagName('tr'); for (var row = 0; row < rowsNotSelected.length; row++) { rowsNotSelected[row].style.backgroundColor = ""; } var rowSelected = table.getElementsByTagName('tr')[rowId]; rowSelected.style.backgroundColor = "red"; } } } window.onload = highlight_row; </script> <table id="mytable"><tr><td>Click me and my background become red</td></tr><tr><td>Click me and my background become red</td></tr></table> which works when I open it with Internet Explorer (when I click on the text, the background become red). I want to load same page on the autoit. I have tried this code but javascript doesn't work (after click on text nothing happens) expandcollapse popup#Include <IE.au3> $html_source = "" & _ '<html><head></head><body>' & _ '<table id="mytable"><tr><td>test</td></tr><tr><td>test2</td></tr></table>' & _ '' & _ '</body></html>' $oIE = _IECreate() _IEBodyWriteHTML($oIE, $html_source) $script = "" & _ "function highlight_row() {" & _ " var table = document.getElementById('mytable');" & _ " var cells = table.getElementsByTagName('td');" & _ " for (var i = 0; i < cells.length; i++) {" & _ " var cell = cells[i];" & _ " cell.onclick = function () {" & _ " var rowId = this.parentNode.rowIndex;" & _ " var rowsNotSelected = table.getElementsByTagName('tr');" & _ " for (var row = 0; row < rowsNotSelected.length; row++) {" & _ " rowsNotSelected[row].style.backgroundColor = '';" & _ " }" & _ " var rowSelected = table.getElementsByTagName('tr')[rowId];" & _ " rowSelected.style.backgroundColor = 'red';" & _ " }" & _ " }" & _ "}" & _ "window.onload = highlight_row;" IEHeadInsertScript($oIE, $script) Func IEHeadInsertScript($o_object, $s_script) Local $o_head, $o_element $o_head = _IETagNameGetCollection($o_object, "head", 0) $o_element = $o_object.document.createElement('script') $o_element.type = 'text/javascript' $o_element.text = $s_script Return $o_head.appendChild($o_element) EndFunc Any idea? Link to comment Share on other sites More sharing options...
Danp2 Posted February 21, 2017 Share Posted February 21, 2017 Use _IEDocWriteHTML instead of _IEBodyWriteHTML -- #Include <IE.au3> $html_source = "" & _ '<html><head>' & _ '<script>' & _ "function highlight_row() {" & _ "var table = document.getElementById('mytable');" & _ "var cells = table.getElementsByTagName('td');" & _ "for (var i = 0; i < cells.length; i++) {" & _ "var cell = cells[i];" & _ "cell.onclick = function () {" & _ "var rowId = this.parentNode.rowIndex;" & _ "var rowsNotSelected = table.getElementsByTagName('tr');" & _ "for (var row = 0; row < rowsNotSelected.length; row++) {" & _ "rowsNotSelected[row].style.backgroundColor = '';" & _ "}" & _ "var rowSelected = table.getElementsByTagName('tr')[rowId];" & _ "rowSelected.style.backgroundColor = 'red';" & _ "}" & _ "}" & _ "}" & _ "window.onload = highlight_row;" & _ '</script>' & _ '</head><body>' & _ '<table id="mytable"><tr><td>test</td></tr><tr><td>test2</td></tr></table>' & _ '' & _ '</body></html>' $oIE = _IECreate() _IEDocWriteHTML($oIE, $html_source) Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
maniootek Posted February 22, 2017 Author Share Posted February 22, 2017 thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now