Welcome guest, is this your first visit? Create Account now to join.
Results 1 to 5 of 5

This is a discussion on Toolstrip help within the Plugins Development section, part of the Chrome Plugins category: Hello everyone. I just began working on my first extension, but have run into a problem that I can't seem ...


  1. #1
    dabomb4eve is offline Junior Member
    Join Date
    Sep 2009
    Posts
    4

    Default Toolstrip help

    Hello everyone.
    I just began working on my first extension, but have run into a problem that I can't seem to fix.

    What I want to do is to get a web page text selection into a JavaScript variable.
    I found a small little script that does such thing, but for me it only works as a link within the same page. What I need it to do is to copy the selected text when the appropriate button on the toolstrip is clicked. Unfortunately, when I click the button, the selection isn't being copied into my script.

    I'm not too sure how the toolstrip is implemented, and have tried various workarounds with none of them working. What I can see is that the moment I click the button, the tab I was in is unfocused (the selected text turns from blue to gray). My theory is that the selection command is not copying it correctly because that tab is no longer the active tab. I have tried using scripts within my toolstrip page, but I am unable to successfully communicate with the other tabs. I have also tried running my selection function onmouseover the button, but that doesn't work either.

    How can I approach this?

  2. #2
    pcki11's Avatar
    pcki11 is offline Senior Member
    Join Date
    Jun 2009
    Posts
    214

    Default

    you have to use content scripts for retrieving content of webpages.

    theme for 2.0.172.43 / 4.0.206.1

  3. #3
    dabomb4eve is offline Junior Member
    Join Date
    Sep 2009
    Posts
    4

    Default

    Cool. Hadn't checked that out. I will definitely give it a try.
    Thanks!

  4. #4
    dabomb4eve is offline Junior Member
    Join Date
    Sep 2009
    Posts
    4

    Default

    Alright, so now this runs much better. I've run into another problem, though.
    My current event listener works, with it being able to acquire the information from the current page.
    I have set up another statement within the listener that listens to a separate event from a custom page of mine upon opening, since having two listeners would cause the second one to never fire. Both pages fire to the same listener with different names, and this works.
    My only problem is that when the custom page opens (by using the toolstrip button), the second listener fails. Upon reloading the page, though, it works, and both event firing are handled correct. Why must I reload my page in order for it to start firing?

    This is a summary of what I have:

    Toolstrip.html

    chrome.extension.onConnect.addListener(function(port) {
    if(port.name == 'hook') {
    var tabID;
    port.onMessage.addListener(function(msg) {
    tabID = msg.tabID;
    document.getElementById('myButton').innerHTML = '<span>'+tabID+'</span>';
    });
    }
    }

    function onToolstripButtonClick() {
    window.open('myPage.html','myPage');
    }

    myPage.html

    var port = chrome.extension.connect({name: 'hook'});
    chrome.tabs.getSelected(null, function(tab) {
    port.postMessage({tabID: (id)});
    });

    The tabID is NOT input into myButton at the time of clicking. Upon reloading, it is. Also, if I were to leave my custom page open, and change the value of myButton, and click it, the tabID, the value IS changed into the tabID. It's only when first opening the page through button clicking that this fails.
    WHY?! I've tried running my script as onload from the body, as well as just as a script. Or is the forwarded message arriving before the listener is active?? I don't know...
    Any help will be appreciated!

  5. #5
    dabomb4eve is offline Junior Member
    Join Date
    Sep 2009
    Posts
    4

    Default

    UPDATE:
    I've been messing around a little more. For my script to run correctly, the reload must be done through the browser (Ctrl + R, F5, Reload button); window.location.reload() doesn't work. Until I reload "correctly", it fails. Afterward, it succeeds without problem.
    !!!

    Also, I managed to modify the two listeners to be separate and not the same listener. Didn't work before...

Similar Threads

  1. [Ext] Toolstrip Address Bar
    By pcki11 in forum Chrome Plugins
    Replies: 14
    Last Post: 07-04-2011, 04:20 PM
  2. Detaching Chrome Toolstrip
    By nandayo in forum Chrome Tips & Tricks
    Replies: 2
    Last Post: 10-09-2009, 12:26 AM
  3. settings for toolstrip
    By libia in forum Plugins Development
    Replies: 3
    Last Post: 08-25-2009, 08:56 PM
  4. Incognito Mode and Extension Toolstrip
    By StevePaul in forum Chrome Troubleshooting
    Replies: 13
    Last Post: 06-20-2009, 10:12 PM
  5. Toolstrip Order?
    By devilslackey in forum Chrome Plugins
    Replies: 1
    Last Post: 06-11-2009, 07:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •