Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JavaScript that refreshes a div

    I’m having some problems with a JavaScript that refreshes a div upon clicking a link the problem is that when It passes the file to the JavaScript there are no line breaks, no divs, and there is another java script within that file this script does not work it seems the script filters everything out is there any way around this. Any help would be greatly appreciated.

    <script language="javascript">
    function loadurl(dest) {
    try {
    xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
    new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) { /* do nothing */ }

    xmlhttp.onreadystatechange = triggered;
    xmlhttp.open("GET", dest);
    xmlhttp.send(null);

    }
    function triggered() {
    if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
    document.getElementById("logreport").innerHTML = xmlhttp.responseText;}
    }
    </script>

    The links

    <a href="javascript:loadurl('files/logs/test.html')">
    <a href="javascript:loadurl('files/logs/test2.html')">

  • #2
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think you'd better post the code of test.html'

    to execute script code callback you should
    split the text wrap by <script> then use function eval(scriptText).

  • #3
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is what test.html looks like

    <html>
    <div id="myContent">
    </div>
    <div id="contentToWrite" style="display:none">
    Port: 2<br>
    IP: xx.xxx.xxx.xxx Port: 2 Time: 4:50:12 PM Date: 4/8/2009 Data: SYN<br>
    IP: xx.xxx.xxx.xxx Port: 2 Time: 4:50:12 PM Date: 4/8/2009 Data: FIN<br>
    </div>
    <script type="text/javascript">
    writeContent(true)
    </script>
    </html>

    do you mean this
    document.getElementById("logreport").innerHTML = eval(xmlhttp.responseText);}

  • #4
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Tried alert(xmlhttp.responseText)
    And go this response from test.html

    <html>
    <div id="myContent">
    </div>
    <div id="contentToWrite" style="display:none">
    Port: 2<br>
    IP: xx.xxx.xxx.xxx Port: 2 Time: 4:50:12 PM Date: 4/8/2009 Data: SYN<br>
    IP: xx.xxx.xxx.xxx Port: 2 Time: 4:50:12 PM Date: 4/8/2009 Data: FIN<br>
    </div>
    <script type="text/javascript">
    writeContent(true)
    </script>
    </html>

    but still no JavaScript activation

  • #5
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok so i fixed this by taking

    <script type="text/javascript">
    writeContent(true)
    </script>
    </html>

    out of test.html and test2.html
    And then replacing this line in the java script

    document.getElementById("logreport").innerHTML = xmlhttp.responseText;}
    with this line
    document.getElementById("logreport").innerHTML = xmlhttp.responseText;writeContent(true);}

    Now I have a different problem
    The script for writeContent is below the problem is that it only works for the first instance of the Div not any other for example if test.html contains this

    <html>
    <div id="myContent">
    </div>
    <div id="contentToWrite" style="display:none">
    Port: 2<br>
    IP: xx.xxx.xxx.xxx Port: 2 Time: 4:50:12 PM Date: 4/8/2009 Data: SYN<br>
    </div>
    </html>

    and test2.html contains this

    <html>
    <div id="myContent">
    </div>
    <div id="contentToWrite" style="display:none">
    Port: 2<br>
    IP: xx.xxx.xxx.xxx Port: 2 Time: 4:50:12 PM Date: 4/8/2009 Data: SYN<br>
    </div>
    </html>

    The script only works for the first html that is opened if i click on the next one it does not work. Any ideas would be greatly appreciated.


    <script language="javascript">
    var charIndex = -1;
    var stringLength = 0;
    var inputText;
    function writeContent(init){
    if(init){
    inputText = document.getElementById('contentToWrite').innerHTML;
    }
    if(charIndex==-1){
    charIndex = 0;
    stringLength = inputText.length;
    }
    var initString = document.getElementById('myContent').innerHTML;
    initString = initString.replace(/<SPAN.*$/gi,"");

    var theChar = inputText.charAt(charIndex);
    var nextFourChars = inputText.substr(charIndex,4);
    if(nextFourChars=='<BR>' || nextFourChars=='<br>'){
    theChar = '<BR>';
    charIndex+=3;
    }
    initString = initString + theChar + "<SPAN id='blink'>_</SPAN>";
    document.getElementById('myContent').innerHTML = initString;

    charIndex = charIndex/1 +1;
    if(charIndex%2==1){
    document.getElementById('blink').style.display='none';
    }else{
    document.getElementById('blink').style.display='inline';
    }

    if(charIndex<=stringLength){
    setTimeout('writeContent(false)',100);
    }else{
    blinkSpan();
    }
    }

    var currentStyle = 'inline';
    function blinkSpan(){
    if(currentStyle=='inline'){
    currentStyle='none';
    }else{
    currentStyle='inline';
    }
    document.getElementById('blink').style.display = currentStyle;
    setTimeout('blinkSpan()',500);

    }
    </script>
    Last edited by merlin214365; 04-18-2009 at 11:22 PM.

  • #6
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the problem of function setTimeout,
    use clearTimeout to stop when click another page
    Last edited by renzaijiang; 04-20-2009 at 11:11 AM.

  • #7
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you works great


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •