How to fill out a textfield within a form on a webpage from a chrome extension?

后端 未结 1 727
深忆病人
深忆病人 2021-02-11 06:31

So far I have got an extension that lists out the webpage the user is on and a button. The button should, when clicked, fill in the textfield with \"testing123\".

On th

1条回答
  •  一整个雨季
    2021-02-11 07:05

    You can't access the webpage directly from popup. You should use content scripts to do this. Content scripts run in the context of the webpage.

    Add this to your manifest :

    "content_scripts": [
            {
                "matches": [
                    "http://www.example.com/*"
                ],
                "js": [
                    "jquery.js",
                    "myscript.js"
                ]
            },
    

    myscript.js :

    $("#body").val("testing123");
    
    document.getElementById('body').value = 'testing123';
    

    0 讨论(0)
提交回复
热议问题