0

I am creating a Chrome extension, with the following code.

File manifest.json

{
"name": "Project",
"version": "1.0.0",
"manifest_version": 2,
"description": "Popup when website requires Log in",
"browser_action":{
    "default_icon":"icon_19.png",
    "default_popup":"Popup.html"
 }
}

File Popup.html

<html>
<head></head>
<body>
<div class="plus" id="plu"></div>
<script src="inline.js"></script>
</body>
</html>

inline.js:

window.onload = function() {
    document.getElementById('plu').onclick=popup;
}
function popup() {
    var link = document.URL;
    alert("This is the link: ( " +link+ " )");
}

When I click the div with the ID 'plu', it gets the URL of file popup.html, but not for the website.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
anandh199g
  • 111
  • 2
  • 3
  • 11
  • possible duplicate of [How can I get the URL for a Google Chrome tab?](http://stackoverflow.com/questions/1979583/how-can-i-get-the-url-for-a-google-chrome-tab) – CBroe Apr 02 '13 at 14:46

1 Answers1

0

The document object at that point refers to your extension's popup window because you're including the script in your popup.html.

You need to use a Content Script if you want to access the DOM of the tab's page. Take a look at:

http://developer.chrome.com/extensions/content_scripts.html

Joe Marini
  • 1,540
  • 2
  • 11
  • 12