James Litewski
James Litewski

Reputation: 449

Is it possible to inject JavaScript that reads 'strings'?

I've heard of 'injecting' JavaScript, but I'm not fully sure on what it does, or how you do it. But I'm wondering if you can inject it into a site in order to read the 'strings' or 'forms'?

For example: Say there's a site that has a field for entering a name. Is there a way to inject JavaScript to make it fill the field with 'James' each time it finds a field requiring a name?

Or would there be a better way to do this?

Upvotes: 0

Views: 188

Answers (2)

wukong
wukong

Reputation: 2597

seems you are looking for content_script or bookmarklet

Upvotes: 1

genesis
genesis

Reputation: 50976

I use this function for userscripts

function ex(function_contents){
    var exec_script = document.createElement('script');
    exec_script.type = 'text/javascript';
    exec_script.textContent = "(" + function_contents.toString() + ")()";
    document.getElementsByTagName('head')[0].appendChild(exec_script);
}

called with

ex(function(){
    document.write("HELLO!");
});

Upvotes: 1

Related Questions