【发布时间】:2018-09-17 22:43:02
【问题描述】:
我是第一次开发 chrome 扩展。它相对简单,我要做的就是在单击按钮时在新选项卡中打开一个网页。但是,我不确定如何在没有 javascript 的情况下执行此操作,因为我知道 chrome 块内联 <script> 元素(或类似的东西)。下面是我的popup.html。
<!DOCTYPE html>
<html>
<head>
<style>
.button {
position: relative;
background-color: #4F5B62;
border: none;
font-size: 28px;
font-family: "Roboto Mono";
font-weight: lighter;
color: #FFFFFF;
opacity: 0.6;
padding: 20px;
width: 200px;
text-align: center;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
text-decoration: none;
overflow: hidden;
cursor: pointer;
border-radius: 12px;
}
.button:hover{
opacity: 1;
}
.button:after {
content: "";
background: #f1f1f1;
display: block;
position: absolute;
padding-top: 300%;
padding-left: 350%;
margin-left: -20px !important;
margin-top: -120%;
opacity: 0;
transition: all 0.8s
}
.button:active:after {
padding: 0;
margin: 0;
opacity: 1;
transition: 0s
}
body{
background-color: #263238;
}
head{
background-color: #263238;
}
</style>
</head>
<body>
<button type="button" class="button">Access chatter</button>
</body>
</html>
任何帮助将不胜感激。
【问题讨论】:
-
只需使用单独的 popup.js 文件和 src 属性:
<script src="popup.js"></script> -
像这样?
-
将您的 JavaScript 放在一个单独的文件中,并使用
script标记将该文件包含在popup.html中,例如<script src="popup.js"></script>。 documentation 中有示例 -
@tomclack 内联 javascript 不允许在 Chrome 扩展中使用。
标签: javascript html json google-chrome google-chrome-extension