简体   繁体   中英

IE9 Alert() now blocks range.select from displaying selected text

I have a button on a page, that when pressed, searches thru data on the form, highlights a certain field, and javascript ALERT()'s the user of the found word. Once the user OK's the ALERT(), the javascript searches and highlights the next occurence of the word, and realerts, and continues this behavior until no further data is found.

Prior to IE9, the below code worked fine to produce this behavior (this is a very simple version of the code, which demonstrates the problem). Normally (prior to IE9) at the pause of the first ALERT(), the text is highlighted on the screen, but under IE9, it is not. With IE9, nothing displays highlighted until after the entire script completes (after the second alert), and at that time only the last found string is highlighted. This prevents the application from stepping thru and highlighting each found word and Alerting the user.

Try running the below under IE9, then under IE8 and below. I don't need to worry in this situation about other browsers, just IE (it is a controlled browser application enviroment):


<html>
<head>
</head>
<body>

<form name="MYFORM">
<input type="text" value="NAME/JONES   ADDR/123 MAIN" name="myinput" size="40">
</form>

<script type="text/javascript" language="JavaScript">

   var range = document.MYFORM.myinput.createTextRange();

   var strFound=range.findText("NAME/");
   range.select();
   alert("Message 1");

   var strFound=range.findText("ADDR/");
   range.select();
   alert("Message 2");

</script>

</body>

Thanks for any insight into fixing the code to work under IE9.

Kevin

You probably need to give the UI time to repaint - do this by splitting your code into sections that can be scheduled using setTimeout(nextIteration, 0); .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM