• Login
    • Search
    • Categories
    • Recent
    • Tags
    • Users
    • Groups
    • Rules
    • Help

    Do more on the web, with a fast and secure browser!

    Download Opera browser with:

    • built-in ad blocker
    • battery saver
    • free VPN
    Download Opera

    Add-on beginner question

    Opera add-ons
    3
    6
    2718
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • absolutelyfreeweb
      absolutelyfreeweb last edited by

      I have looked at the Hellow World, pop up, and tabs developer pages.

      I am attempting to create a combination now without success.

      What I want is a popup, that has a link, when I click the link, it should update the current tab.

      So, I was thinking a script on the html page, using the script for tabs.

      There are obstacles:
      1 - the script code adds a listener. Can I add a listener to my link in the web page? I don't need a listener, I simply want to say, user clicked, you go and update the page.

      2 - the script is diabled by security. I have enabled tabs in the manifest but this is beyond that.

      I get:

      Refused to execute inline event handler because it violates the following content security policy directive: script-src self blob filesystem chrome-extension-resource. Either the unsafe-inline keyword, a hash sha256.. or a nonce nonce- is required to enable inline execution.

      Could you help me?

      (sorry for the double post)

      (if it matters I'm on opera 38)

      Reply Quote 0
        1 Reply Last reply
      • absolutelyfreeweb
        absolutelyfreeweb last edited by

        ok so I put my javascript code outside the html to avoid security problems and do not get that error anymore, but it's like the js file does not access the html file. I've tried both:

        document.getElementById('linkspan').appendChild(link);
        document.getElementsByTagName("body")[0].appendChild(link)

        but get:

        uncaught typer error: Cannot read property appendChild of null
        uncaught typer error: Cannot read property appendChild of undefined

        Reply Quote 0
          1 Reply Last reply
        • absolutelyfreeweb
          absolutelyfreeweb last edited by

          when I enumerate the page with:
          for (i = 0; i < document.all.length; i++) {
          alert(document.all[i].nodeName);

          I get:
          HTML, HEAD, STYLE, SCRIPT only...

          no body!!

          my html is very simple, I don't know how to post the source in this forum... O.O

          Reply Quote 0
            1 Reply Last reply
          • leocg
            leocg Moderator Volunteer last edited by

            my html is very simple, I don't know how to post the source in this forum.

            Store it somewhere and put the link here.

            Maybe this page has some info for you.

            Reply Quote 0
              1 Reply Last reply
            • absolutelyfreeweb
              absolutelyfreeweb last edited by

              thank you leoc, that was bc can't use onload trigger in page, so script tag had to come last in the html page.

              now back to original question, how do I from javascript referenced from my popup page, change location of active tab?

              the link in the popup page, calls a javascript function onclick, if I try to set chrome.tab[0].url the tab[0] is undefined

              Reply Quote 0
                1 Reply Last reply
              • kroppy
                kroppy last edited by

                First of all, you don't change url directly and you need permissions for tabs in your manifest file, to have access to tabs API
                add this to manifest.json file:

                "permissions": ["tabs"]

                Then when you wan't to change url in active tab, you have to do it in two steps,
                get active tabId and inside of callback function you can change url, like so:

                chrome.tabs.query({active: true}, function(tabs){
                chrome.tabs.update(tabs[0].id, {url: "your url here"}, function(){});
                });

                Anyway you should take a look at chrome's API:
                https://developer.chrome.com/extensions/tabs#method-query

                Hope that helps. 😃

                Reply Quote 0
                  1 Reply Last reply
                • First post
                  Last post

                Computer browsers

                • Opera for Windows
                • Opera for Mac
                • Opera for Linux
                • Opera beta version
                • Opera USB

                Mobile browsers

                • Opera for Android
                • Opera Mini
                • Opera Touch
                • Opera for basic phones

                • Add-ons
                • Opera account
                • Wallpapers
                • Opera Ads

                • Help & support
                • Opera blogs
                • Opera forums
                • Dev.Opera

                • Security
                • Privacy
                • Cookies Policy
                • EULA
                • Terms of Service

                • About Opera
                • Press info
                • Jobs
                • Investors
                • Become a partner
                • Contact us

                Follow Opera

                • Opera - Facebook
                • Opera - Twitter
                • Opera - YouTube
                • Opera - LinkedIn
                • Opera - Instagram

                © Opera Software 1995-2025