Parsing html output and executing javascript

Posted by user1841964 on Stack Overflow See other posts from Stack Overflow or by user1841964
Published on 2012-12-14T18:36:05Z Indexed on 2012/12/15 23:04 UTC
Read the original article Hit count: 136

Filed under:
|
|

I have this function:

function parseScript(_source) {
    var source = _source;
    var scripts = new Array();

    while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
        var s = source.indexOf("<script");
        var s_e = source.indexOf(">", s);
        var e = source.indexOf("</script", s);
        var e_e = source.indexOf(">", e);

        scripts.push(source.substring(s_e+1, e));
        source = source.substring(0, s) + source.substring(e_e+1);
    }
    for(var i=0; i<scripts.length; i++) {
        try {
            eval(scripts[i]);
        }
        catch(ex) {
        }
    }
    return source;
}

It parses and execute Javascript wonderfully except the when in <script type='text/javascript' src='scripts/gen_validatorv31.js'></script> the src file never gets executed.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html