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

This is a discussion on Send clicked hyperlink via POST within the Plugins Development section, part of the Chrome Plugins category: Hello all, i am making an extension that does the following thing: When I right click on a hyperlink that ...


  1. #1
    babbelut is offline Junior Member
    Join Date
    Oct 2010
    Posts
    1

    Default Send clicked hyperlink via POST

    Hello all,

    i am making an extension that does the following thing:

    When I right click on a hyperlink that ends with .torrent I can click on "Send to Transmission" in the contextmenu.
    The string of the hyperlink will be send via the POST form.

    This is my first extension so i'm still learning. Can you please help me?
    This is what I got so far:


    <script>
    function DownTrans()
    {
    <form action="http://x.x.x.x:9091/transmission/web/" method="post" id="torrent_upload_form" enctype="multipart/form-data" target="torrent_upload_frame">
    <input type="text" id="torrent_upload_url">
    <input type="checkbox" id="torrent_auto_start">
    </form>
    }
    chrome.contextMenus.create({title: "Download met Transmission", contexts:["link"], onclick: DownTrans});
    </script>

  2. #2
    xlilien is offline Junior Member
    Join Date
    Oct 2010
    Posts
    2

    Default

    What exactly is not working for you? Did you try the debugger?

    First of all, I am a beginner too, so if I give you a lame answer, dont be mad ;-). I think that what we see here is a popup.html which is called from your manifest.json, right?

    In my opinion, the mistake is that you mix html code where javascript input is expected. I have written a little bit similar extension, which takes some data from xml and creates hyperlinks in the popup.html, after clicking new tab is opened on a specified page with variables taken from the hyperlink. This is my code:

    Code:
    <script>
    var req = new XMLHttpRequest();
    req.open("GET", chrome.extension.getURL('/contacts.xml'), true);
    // after being loaded, I display hyperlinks in popup.html        
    req.onload = displayContacts;
    req.send(null);
    
    // function to create html part - hyperlinks
    function displayContacts() {
      var contacts = req.responseXML.getElementsByTagName("contact");
      for (var i = 0, contact; contact = contacts[i]; i++) { 
        var div = document.createElement("div");
            div.setAttribute('onclick', 'click(this)');
            div.setAttribute('style', 'padding-left: 5px; padding-right: 15px;');
            div.id = contact.getElementsByTagName("number")[0].childNodes[0].nodeValue;
            
        var spanName = document.createElement("span");
            spanName.setAttribute('style', 'font-weight: bold; padding-left: 5px;');
            spanName.appendChild(document.createTextNode(contact.getElementsByTagName("name")[0].childNodes[0].nodeValue));
            
        var spanNumber = document.createElement("span");
            spanNumber.setAttribute('style', 'font-style: italic; padding-left: 5px;');
            spanNumber.appendChild(document.createTextNode("(" + contact.getElementsByTagName("number")[0].childNodes[0].nodeValue + "}"));        
    
        div.appendChild(spanName);
        div.appendChild(spanNumber);
        document.body.appendChild(div);
    
        // the result look like this: 
        // <div onclick="click(this)" style="padding-left: 5px; padding-right: 15px;" id="608905278"><span style="font-weight: bold; padding-left: 5px;">Name</span><span style="font-style: italic; padding-left: 5px;">(111222333}</span></div>
      }
    }
    
    // function to create new tab with specific variable at the end
    function click(number) {
      chrome.tabs.create({url:("http://something.net?number=" + number.id )});       
    }
    </script>
    <body>
    <h1>Some headline here-html input</h1>
    </body>
    So this is my code, I hope it helps you a little. If you have any other questions, let me know and I will try to answer them.

Similar Threads

  1. [STRANGE BEHAVIOR] Orange border around clicked links
    By ilbane in forum Chrome Troubleshooting
    Replies: 9
    Last Post: 01-12-2012, 09:06 AM
  2. what happend to my post?
    By sleepwalker in forum General Chat
    Replies: 0
    Last Post: 04-26-2010, 04:51 PM
  3. My 1st Post
    By Heyyou in forum General Chat
    Replies: 2
    Last Post: 02-08-2010, 10:05 AM
  4. [New Ext] Send Link (PageAction)
    By Clams in forum Chrome Plugins
    Replies: 1
    Last Post: 09-18-2009, 05:55 AM

Posting Permissions

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