Chrome extension to redirect tab to my page

后端 未结 3 970
醉话见心
醉话见心 2021-01-01 06:40

I am new to chrome extensions and I am having trouble while writing my first extension for chrome. What I am trying to do is detect the new tab action and redirect to a pre-

3条回答
  •  無奈伤痛
    2021-01-01 07:29

    If you want to over ride a default page, you shoud use html file, not a js file. And if you just want to over ride a page, you do not need any background page or content script. Here is the sample code:

    menifest.json:

    {
        "name": "Tabber",
        "manifest_version" : 2,
        "version": "1.0",
        "description": "MyExtension",
        "chrome_url_overrides": {
            "newtab": "my.html"
        },
        "permissions": [
            "tabs"
        ]
    }
    

    my.html:

    
    
    
        over ride page   
        
    
        
    
    
    

    code.js:

    window.open("http://www.google.com", "_self");
    

    Note: you can not write any js in your html file. You need to include js file in html file.

    And, you even do not need any js file. just modify the my.html as this:

    
        
    
    

提交回复
热议问题