Rewriting itself

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • laszlo

    Rewriting itself

    The function below (as fc.js) works with IE6.0, NS4.2 NS7.1. It
    rewrites itself increasing the number.

    However if I comment out the othervise unnecessary window.alert, it
    still works with NS but falls into and endless loop in IE. The alert
    helps only after the scr=fc.js line, otherwise the first recursion
    causes the endless loop in IE

    Any cue for the reason or more preferably workaround is appreciated. I
    include the text for fc.js and the calling test.html

    laszlo

    ***** fc.js *****

    function testrut(cnt) {
    var teststr = "Hello";
    var nwf = window.open("", "testecske" , "width=200,heig ht=200");

    cnt++;

    nwf.document.wr iteln("<HTML><H EAD>");
    nwf.document.wr iteln("<TITLE>r ecursive javascript</TITLE></HEAD>");

    nwf.document.wr iteln("<BODY BGCOLOR=silver ><FORM><CENTER> ");
    nwf.document.wr iteln(teststr + cnt + "<BR><BR>") ;
    nwf.document.wr iteln("<INPUT TYPE=BUTTON VALUE=repeat
    onclick='testru t(" + cnt + ");'><BR><BR>") ;
    nwf.document.wr iteln("<INPUT TYPE=BUTTON VALUE=close
    onclick='window .close();'><BR> <BR>");
    nwf.document.wr iteln("</CENTER></FORM>");
    nwf.document.wr iteln("<SCRIPT LANGUAGE='JavaS cript1.2'
    SRC='fc.js'></SCRIPT>");
    nwf.document.wr iteln("</BODY></HTML>");
    window.alert('h ohoho');
    nwf.document.cl ose();
    }

    ***** test.html *****


    <HTML><HEAD>
    <SCRIPT LANGUAGE='JavaS cript1.2' SRC='fc.js'></SCRIPT>
    <TITLE>Test</TITLE></HEAD>
    <BODY><FORM><CE NTER>
    <INPUT TYPE=BUTTON VALUE=start onclick=testrut (0);>
    </CENTER></BODY></HTML>
  • laszlo

    #2
    Re: Rewriting itself

    I've get no answer, but fortunatelly found the resolution. The trick
    is to put a hidden button into the calling html, set the id as
    parameter, and for rewriting click this button from javascript. This
    seems to be w/o hazard.



    *** fc.js ****
    function testrut(name1, name2) {
    var widget = document.getEle mentById(name1) ;
    var cnt = widget.value;
    cnt = cnt.replace(/rrr/i, '');
    var teststr = "Hello=" + cnt;
    cnt = parseInt(cnt) +1;
    var nwf = window.open("", "testecske" , "width=200,heig ht=200");
    nwf.document.wr iteln("<HTML><H EAD>");
    nwf.document.wr iteln("<SCRIPT TYPE='text/JavaScript'
    LANGUAGE=JavaSc ript1.2>");
    nwf.document.wr iteln("var id1='" + name1 + "'");
    nwf.document.wr iteln("var id2='" + name2 + "'");
    nwf.document.wr iteln("function finish(flag) {");
    nwf.document.wr iteln("var widget =
    window.opener.d ocument.getElem entById(id1);") ;
    nwf.document.wr iteln("widget.v alue = '' + " + cnt + ";");
    nwf.document.wr iteln("if (flag)
    window.opener.d ocument.getElem entById(id2).cl ick();");
    nwf.document.wr iteln("else window.close(); ");
    nwf.document.wr iteln("}");
    nwf.document.wr iteln("</SCRIPT>");
    nwf.document.wr iteln("<TITLE>r ecursive javascript</TITLE></HEAD>");

    nwf.document.wr iteln("<BODY BGCOLOR=silver ><FORM><CENTER> ");
    nwf.document.wr iteln(teststr + "<BR><BR>") ;
    nwf.document.wr iteln("<INPUT TYPE=BUTTON VALUE=repeat
    onclick='finish (1)'><BR><BR>") ;
    nwf.document.wr iteln("<INPUT TYPE=BUTTON VALUE=close
    onclick='finish (0);'><BR><BR>" );
    nwf.document.wr iteln("</CENTER></FORM>");
    nwf.document.wr iteln("</BODY></HTML>");
    nwf.document.cl ose();
    }

    *** recurse.html ***

    <HTML><HEAD>
    <SCRIPT LANGUAGE='JavaS cript1.2' SRC='fc.js'></SCRIPT>
    <TITLE>Test</TITLE></HEAD>
    <BODY><FORM><CE NTER>
    <INPUT TYPE=TEXT SIZE=8 NAME='I0' ID='I0' VALUE=1>
    <SPAN STYLE={visibili ty:hidden}>
    <INPUT TYPE=BUTTON ID='I1' NAME='I1' VALUE='' onclick='testru t("I0",
    "I1");'> </SPAN>
    <INPUT TYPE=BUTTON VALUE='start' onclick='testru t("I0", "I1");'>
    </CENTER></FORM></BODY></HTML>

    Comment

    Working...