Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

set time out in JavaScript

Firefox always loads dynamic images, but IE it just shows images without any dynamic action. what changes I need to do?

JavaScript code from IE view source code:

<script type=”text/javascript”
    <!--/*--><![CDATA[/*><!--*/ 
    if (document.getElementById("safeForm1d3").submitted.value == "false") { 
      document.getElementById("safeForm1d3").submitted.value = "true"; 
      setTimeout('document.getElementById("safeForm1d3").submit()', 100); 
    }else{ 
    document.getElementById("toHide").style.display="none"; 
    }/*-->]]>*/
</script>

I am using Wicket framework, so real java code is:

 static private class SafeSubmitBehaviour extends AbstractBehavior{
    public void onRendered( Component component ) {
      super.onRendered( component );      
      StringBuffer buffer = new StringBuffer(200);
      buffer.append("<script type="text/javascript" ><!--/*--><![CDATA[/*><!--*/
");
      buffer.append("if (document.getElementById("").append(component.getMarkupId()).append("").submitted.value == "false") {
");
      buffer.append("document.getElementById("").append(component.getMarkupId()).append("").submitted.value = "true";
");
      buffer.append("setTimeout('document.getElementById("").append(component.getMarkupId()).append("").submit()', 100);
}else{
");
      buffer.append("document.getElementById("toHide").style.display="none";
}/*-->]]>*/</script>");      
      component.getResponse().write(buffer);
    }  
  } 

html page which loads my dynamic image is:

<div id="toHide" class="pb-text-align-center">
        <img style="display: inline" src="img/load.gif" />
            <form wicket:id="safeForm" class="clearfix">
            <input type="hidden" wicket:id="submitted" value="false" />
        </form>
</div>
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Because setTimeout() requires your function to be passed as a string or as an anonymous function:

setTimeout(function() { document.getElementById("safeFormec").submit(); }, 100);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...