简体   繁体   中英

Get javascript function parameters

I am trying to write a code for Greasemonkey. I can handle the tagnames, ids etc. But I got stuck in the 'script' tag. I can get the innerHTML of this script tag. But I want to get the input parameters only of the 'on' function, specifically 4th input which is a number. And store them in an array.

<ol id="online1">
        <script language="javascript" >
            on('0','2','abc','401757','');
    on('1','1','asd','1115337','');
    on('2','2','asdsad','1169333','');
    gi('asdasd','10453','');
    gi('asdasd','10453','');
.
.
.
.
</script>

Should result in

array = [401757,1115337,1169333];

I can get the innerHTML of the script like this:

window.frames[2].document.getElementById('online1').getElementsByTagName('script')[0].innerHTML

As per your example, you can just use .split() on the innerHTML using , as a delimiter. If you want, you can add in an extra safeguard and use a function to detect whether you're getting a number .

JavaScript:

var vals = document.getElementsByTagName('script')[2].innerHTML.split(',');
for(var i = 3; i < vals.length; i+=4)
{
    console.log(vals[i]);
}

Output:

'401757'
'1115337'
'1169333'
'10453'

jsFiddle

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