Monday, April 2, 2007

page.select and IE

Hey!

I had an earlier post about testing the RJS command page.select. I've found further reason not to use it in the situation it was in. The problem began because originally I had something like:

page.replace_html "somediv", "somecontent"

This was causing a javascript exception sometimes because "somediv" was not always guaranteed to be on the page. My solution was to use the built in page.select in rails:


page.select("somediv").each do |value|
page.replace_html value, "something"
end

I would imagine mapping IDs to DOM elements would be an O(1) operation, but ... in internet explorer 6 it causes the whole application to freeze for a second or two if "somediv" is not present in the DOM. Not the behavior you'd want for a minor AJAX action. The RJS solution:

page << "if ($('somediv')) {"
page.replace_html "somediv", "some content"
page << "}"

No comments: