Note that there are some explanatory texts on larger screens.

plurals
  1. POStopping content script in chrome extension
    primarykey
    data
    text
    <p>I have developed chrome extension , I have added ,</p> <pre><code> chrome.browserAction.onClicked.addListener </code></pre> <p>which will start the script once clicked on , the script in turn will add a div at the bottom of the web page on the tab the browser action is clicked , </p> <p>All I have to do is , I need to add a close link which will stop the content script and close the div at the bottom ,</p> <p>I have tried windows.close() , self.close() but nothing seems to work ,I would atleast want it to work in a way that 2nd time some one clicks on browser action, the script should stop.</p> <p>Here is my code,</p> <p>background.js</p> <pre><code> chrome.browserAction.onClicked.addListener( function() { chrome.tabs.executeScript( { file: 'myscript.js' } ); }); </code></pre> <p>myscript.js</p> <pre><code>document.body.appendChild(div); document.addEventListener("click", function (e) { e.preventDefault(); var check = e.target.getAttribute("id"); var check_class = e.target.getAttribute("class"); if(check=="ospy_" || check=="ospy_id" || check=="ospy_text" || check=="ospy_el" || check=="ospy_class" || check=="ospy_name" || check=="ospy_href" || check=="ospy_src"|| check=="ospy_wrapper"|| check=="ospy_style"|| check=="ospy_rx"|| check=="ospy_con"|| check_class=="ospy_td"|| check=="ospy_main_tab"|| check_class=="ospy_tab" || check_class=="ospy_ip"|| check_class=="ospy_lab") { } else{ document.getElementById('ospy_id').value = ""; document.getElementById('ospy_class').value = ""; document.getElementById('ospy_el').value = ""; document.getElementById('ospy_name').value = ""; document.getElementById('ospy_style').value = ""; document.getElementById('ospy_href').value = ""; document.getElementById('ospy_text').value = ""; document.getElementById('ospy_src').value = ""; document.getElementById('ospy_con').value = ""; document.getElementById('ospy_').value = ""; document.getElementById('ospy_rx').value = ""; var dom_id=e.target.getAttribute("id"); // var dom_id = e.target.id.toString(); var dom_name = e.target.name.toString(); var dom_class = e.target.className.toString(); // var dom_class = this.class; var dom_html = e.target.innerHTML; var dom_href = e.target.getAttribute("href"); var dom_text = e.target.text; var dom_el= e.target.tagName; var dom_src= e.target.src; //var XPATH = e.target.innerHTML; var rel_xpath = ""; var field =""; var field_value = ""; field="id"; field_value = dom_id; rel_xpath = dom_el+"[@"+field+"='"+field_value+"']"; if(dom_id == null){ field="href"; field_value= dom_href; //var rel_xpath = dom_el+"[contains(text(), '"+dom_text+"')]"; rel_xpath = dom_el+"[@"+field+"='"+field_value+"']"; if(dom_href==null || dom_href=="#") { field="src"; field_value= dom_src; rel_xpath = dom_el+"[@"+field+"='"+field_value+"']"; //rel_xpath = "nope nothing"; if(dom_src==null) { var rel_xpath = dom_el+"[contains(text(), '"+dom_text+"')]"; if(dom_text=="") { field="class"; field_value= dom_class; rel_xpath = dom_el+"[@"+field+"='"+field_value+"']"; } } } } var con_xpath = ""; var con_xpath = dom_el+"[contains(text(), '"+dom_text+"')]"; if(dom_text==null) { con_xpath = "NA"; } var css ="color: "; css += getComputedStyle(e.target).color; css +="\nWidth: "; css += getComputedStyle(e.target).width; css +="\nHeight: "; css += getComputedStyle(e.target).height; css +="\nbg: "; css += getComputedStyle(e.target).background; css +="\nfont: "; css += getComputedStyle(e.target).font; css +="\nvertical-align: "; css += getComputedStyle(e.target).verticalalign; css +="\nmargin: "; css += getComputedStyle(e.target).margin; var node = getXPath(e.target.parentNode); document.getElementById('ospy_id').value = dom_id; document.getElementById('ospy_class').value = dom_class; document.getElementById('ospy_el').value = dom_el; document.getElementById('ospy_name').value = dom_name; document.getElementById('ospy_style').value = css; document.getElementById('ospy_href').value = dom_href; document.getElementById('ospy_text').value = dom_text; document.getElementById('ospy_src').value = dom_src; document.getElementById('ospy_').value = node; document.getElementById('ospy_rx').value =rel_xpath; document.getElementById('ospy_con').value =con_xpath; }}, false); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload