I have struggled for some time trying to figure out why my code wont run in a Chrome Browser Action Extension. If I build it all as a single HTML page and run it in a test it works fine. When I try to put the HTML in the "popup.html" file and then add the jquery code to my popup.js (Which contains some javascript that already works) it will not work. Basic action is: When extension icon is clicked, user sees 2 buttons to "add Link" or "Add Doc" When clicked, each button toggles open/closed a different iframe. Button tooltip also displays on hover. I am a novice programmer and fear I am missing something easy. What am I doing wrong?
Here is popup.html file
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="popup.js"></script>
</head>
<body>
<h1>My Web Page</h1>
<p> click the button to get the current tab URL for cut/paste <button id="myBtn"> Try it</button> </p>
<p id="demo">Url displays Here</p>
<button id= 'link'> Add Link </button> <button id='Doc'> Add Doc </button>
<div id="testdiv">
<iframe height="400" allowTransparency="true" frameborder="0" scrolling="yes" style="width:400;border:none" src="https://wufoo.com"><a href="https://wufoo.com">Fill out my Wufoo form!</a></iframe>
</div>
<div id="testdiv2">
<iframe height="400" allowTransparency="true" frameborder="0" scrolling="yes" style="width:400;border:none" src="https://wufoo.com"><a href="https://wufoo.com"">Fill out my Wufoo form!</a></iframe>
</div>
</body>
</html>
Here is the popup.js file
//----Here is jquery script for button tooltip on hover-----
$('#link').mouseenter(function(){
$('body').append("<div id='linkTooltip' style='position:fixed;'></div>");
$('#linkTooltip').html("Add a Web Link to your Portal");
$('#linkTooltip').css({
"top" : $(this).offset().top + MYTOPOFFSET,
"left" : $(this).offset().left + MYLEFTOFFSET
});
});
$('#link').mouseleave(function(){
$('#linkTooltip').remove();
});
$('#Doc').mouseenter(function(){
$('body').append("<div id='DocTooltip' style='position:fixed;'></div>");
$('#DocTooltip').html("Add a Document or online link to a document");
$('#DocTooltip').css({
"top" : $(this).offset().top + MYTOPOFFSET,
"left" : $(this).offset().left + MYLEFTOFFSET
});
});
$('#Doc').mouseleave(function(){
$('#DocTooltip').remove();
});
//--------Here is the jquery script to toggle the iframes when button clicked.
$(document).ready(function(){
$("#testdiv").hide()
$("#link").click(function(){
$("#testdiv").toggle()
});
});
$(document).ready(function(){
$("#testdiv2").hide()
$("#Doc").click(function(){
$("#testdiv2").toggle()
});
});
Manifest file is:
"manifest_version": 2,
"name": "IT Vendorconnect Sample",
"description": "This extension launches Wufoo Form on current page",
"version": "1.0",
"icons": { "128": "ITVCicon128x128.png" },
"browser_action": {
"default_icon": "ITVCicon.png",
"default_popup": "popup.html"
},
//---------------
"content_scripts": [ {
"js": [ "jquery.min.js", "popup.js" ],
"matches": [ "http://*/*", "https://*/*"]
}],
//---------------
"permissions": [ "tabs", "activeTab"
] }