javascript - Uncaught TypeError: Cannot read property '0' of null in Chrome extension -
i'm trying create google extension, , among problems had while doing so, had problem can't figure out how fix looking @ soooo answers in stackoverflow.
basically, code supposed open popup replaces existing popup when click on link in popup.
so code, when click on "clickme" link, opens "popup2.html". maybe answer obvious, javascript knowledges more rusty...
var hrefs = document.getelementbyid("clickme"); function openlink() { var href = this.href; chrome.tabs.query({active: true, currentwindow: true}, function(tabs) { var tab = tabs[0]; chrome.tabs.update(tab.id, {url: href}); }); } (var i=0,a; a=hrefs[i]; ++i) { hrefs[i].addeventlistener('click', openlink); } document.getelementbyid('clickme').addeventlistener('click', hello);
thank in advance !
the problem accessing 0 property hrefs
variable, null.
hrefs[i].addeventlistener('click', openlink);
your code assumes hrefs
holds array domelement. i
0 in case. loop infinite loop guess.
Comments
Post a Comment