简体   繁体   English

来自Google Chrome的弹出式扩展程序的JS警报

[英]JS Alerts from a popup extension in google chrome

i've made my very first google chrome extension. 我做了我的第一个谷歌浏览器扩展程序。 i've found out i can't show a javascript alert from the extension popup. 我发现我无法从扩展名弹出窗口中显示JavaScript警报。 Is there a way i can enable the extension to show it? 有没有一种方法可以使扩展显示它? or is there better way to do it without using alerts? 还是有更好的方法而不使用警报? I'm a student, this might be the easiest extension ever but i need your help here's the link to the code 我是学生,这可能是有史以来最简单的扩展,但是我需要您的帮助, 这是代码的链接

I'm guessing you want to use an alert so that you can debug your extension. 我猜您想使用一个警报,以便您可以调试扩展程序。

I've found it easier to get your extension to show its main window, right click on it, and then click on "inspect element". 我发现让您的扩展程序显示其主窗口更容易,右键单击它,然后单击“检查元素”。 This then lets you get to it through the Chrome debugger. 然后,您可以通过Chrome调试器进行操作。

Does this help? 这有帮助吗?

[ADDED] [添加]

My apologies. 我很抱歉。 If you want to alert the end-user, a Content Script may be the way to go. 如果您想警告最终用户,可以使用内容脚本 Content scripts can manipulate the DOM, so you can easily add your "alert" as perhaps a DIV that lights up when appropriate. 内容脚本可以操纵DOM,因此您可以轻松地添加“警报”作为DIV,并在适当时亮起。

You cannot directly inline javascript code inside chrome extension html files. 您无法在chrome扩展html文件中直接内联javascript代码。 Chrome probably throws an error that could see by inspecting the popup with the debugger (follow Ram Rajamony instructions for this). Chrome可能会抛出一个错误,可以通过使用调试器检查弹出窗口来查看(按照Ram Ramamony的说明进行操作)。

The solution is to put your javascript in a js file beside the html, and include it in the popup html file. 解决方案是将您的JavaScript放在html旁边的js文件中,并将其包含在弹出html文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM