irfan harun irfan harun - 1 year ago 75
Javascript Question

How to grab data from one tab and paste it to another tab using greasemonkey

I want to grab some data from a page opened in one tab, and paste it into a textarea of another page opened in another browser tab. How can I do this with Javascript and Greasemonkey?

Answer Source
  1. Set both domains in the metadata block so the script will be activated on both pages
  2. Find an unique element in both websites from which you can detect which page you are currently on.
  3. If you are on the page with the table, get the data and put it with GM_setValue in the store. If needed, open the next website by using GM_openInTab.
  4. If the next website gets detected, retrieve the stored value with GM_getValue and paste it into the textarea.

Not this hard over Greasemonkey, even though its necessary to load the textarea-page AFTER the table-page.


// @include*
// @include*
// @require

$(document).ready(function() {
    if( $("#divfromsite1").length )
       GM_setValue("pastetext", $("#gettable").html() );
       $("#pastetextarea").val( GM_getValue("pastetext","") );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download