-1

I can't seem to get this to work. I've looked for an answer but nothing seems to help me. I had a working version as an html page, but I cannot get it to work as an extension. This is my first extension so if I am doing something wrong please notify me so.

manifest.json:

{
"manifest_version": 2,

"name": "ROBLOX User-Profile Finder",
"description": "Find any user's profile by typing in their name.",
"version": "1.0",

"permissions": [
"<all_urls>"
],
"browser_action": {
"default_icon": "Icon.png",
"default_popup": "Popup.html"
}
}

Popup.html:

<!DOCTYPE html>
<html>
<head>
<script>
var link="http://roblox.com/user.aspx?username=";
function Submit(user) {
window.open(link.concat(user));
}
</script>
</head>

<body>
<p>Type in the roblox username:</p>
<input type="text" id="username" value="">
<button type="button" onclick="Submit(window.getElementById('username').value)">Go to Profile!</button>
</body>

</html>

What is the problem here? I think I'm missing something, as I usually program in Lua, not JavaScript.


Solved: The problem was that I was making scripts in the middle, and I kept asking for help, the problem was a simple mistake with the quotation marks and a few other little errors. Here's the finished scripts if anyone's interested:

manifest.json:

{
    "manifest_version": 2,

    "name": "ROBLOX User-Profile Finder",
    "description": "Find any user's profile by typing in their name. Note: Not created by roblox.",
    "version": "1.0",

    "permissions": [
    "<all_urls>"
  ],
  "browser_action": {
    "default_icon": "Icon.png",
    "default_popup": "Popup.html"
  }
}

Popup.html:

<!DOCTYPE html>
<html>
    <head>
        <p>Type in the roblox username:</p>
        <input type="text" id="username" value="">
        <button type="button" id="Button">Go to Profile!</button>
    </head>
    <body>
        <script src="Script.js"></script>
    </body>

</html>

Script.js:

var link="http://roblox.com/user.aspx?username=";
function Submit() {
    window.open(link.concat(document.getElementById("username").value));
}

document.getElementById('Button').addEventListener("click", Submit);
Cœur
  • 32,421
  • 21
  • 173
  • 232
warspyking
  • 2,767
  • 2
  • 15
  • 33
  • I would really appreciate any help. – warspyking Aug 26 '14 at 20:31
  • 2
    Could you please not edit the original code? The answer and its comments no longer make sense. Instead, could you post the latest version as an addition to your original post? – Teepeemm Aug 26 '14 at 21:53
  • are there any errors in Chrome devtools (F12) ? – pomeh Aug 26 '14 at 22:09
  • @Tee Thanks, I'll keep that in mind for future questions. – warspyking Aug 26 '14 at 22:34
  • The console won't be at F12. Right-click your extension's button and select "Inspect popup". – Xan Aug 26 '14 at 22:57
  • @Xan good to know. I was wondering why nothing appeared at the console lol. – warspyking Aug 27 '14 at 01:38
  • I have rolled back your last edit. Please post the solution you found in the end as an answer. – Xan Aug 27 '14 at 12:20
  • Can't we just put it back... I'll remember to update with an answer next time, ATM I don't have access to the source. Unless you'd put the answer there, in which case it'll benefit us both (and others with the same problem) – warspyking Aug 27 '14 at 16:19
  • If you need to get the source of an edit, you can click "edited ..." right above the last person to edit the post. The reason we don't want to edit away useful information is that we want this site to be useful to anyone else that comes across this post. – Teepeemm Aug 29 '14 at 16:28
  • I'll be updating this with the correct code next time I'm on laptop, I should've done this long ago. I'm fixing up my posts because of my post-ban. – warspyking Sep 21 '14 at 16:26

1 Answers1

2

First of all, next time you'd want to use developer tools (F12) and go to the console tab to see the errors.

Now as to your specific problem, you can't run inline code in Chrome extensions.

This will not work:

<button type="button" onclick="Submit(window.getElementById('username').value)">Go to Profile!</button>


You need to write an external .js file and put all the event bindings of your buttons in there. So by the end of the process your .js file will be:

function myClickFunction() {
    //click logic goes here
}
document.getElementById('myButton').addEventListener("click", myClickFunction);

and your .html will look like this:

<button type="button" id="myButton">Go to Profile!</button>
MeLight
  • 5,136
  • 2
  • 35
  • 61