[英]Chrome extension - Custom alert box on pageload
I want to make a custom alertbox that executes on page load, as the default 我想创建一个自定义警报框,该警报框在页面加载时执行,作为默认设置
alert('hello');
is very ugly & I believe annoying for user interaction. 非常难看,我认为用户互动很烦人。
My current code is: 我当前的代码是:
manifesto.js manifesto.js
"content_scripts": [
{
"matches": ["http://www.google.com"],
"js": ["alert.js"]
}
]
alert.js alert.js
window.onload = function()
{
if(document.body.innerHTML.toString().indexOf('google') > -1 {
alert('Hello Google');
}
}
which will execute an alarm box if the user is on google.com, but I want something a bit prettier, I've tried using notifications but unfortunately it doesn't seem as though you can implement it via content_scripts. 如果用户位于google.com上,它将执行一个警报框,但是我想更漂亮一些,我尝试使用通知,但不幸的是,似乎不能通过content_scripts实现它。 So my current route is to produce a friendly custom alertbox
所以我目前的方法是制作一个友好的自定义警报框
If you want to make a modal box (which you could use as an alert) I'd suggest a11y-dialog . 如果您想制作一个模式框(您可以将其用作警报),建议您使用a11y-dialog 。
You could use the example from https://github.com/edenspiekermann/a11y-dialog/blob/master/example/index.html and call dialog.show();
您可以使用https://github.com/edenspiekermann/a11y-dialog/blob/master/example/index.html中的示例,然后调用
dialog.show();
inside that 在里面
window.onload = function()
{
if(document.body.innerHTML.toString().indexOf('google') > -1 {
//code to make the html e.g. document.createElement...
dialog.show(); //to force the modal/alert to show
}
}
Hope that helps, otherwise you could look at message passing to tell a background script when to show the chrome notification 希望对您有所帮助,否则您可以查看消息传递以告诉后台脚本何时显示chrome通知
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.