DOM修改弹出窗口或标签在chrome扩展立即撤消一旦脚本完成
DOM modifications to popup or tab in chrome extension instantly undone once script completes
单击BrowserAction时,test.html
在新选项卡中打开。这工作如预期。这里是background.js
:
chrome.browserAction.onClicked.addListener(function () {
chrome.tabs.create({
url: "./test.html"
});
});
这里是test.html
:
<!DOCTYPE HTML>
<head>
</head>
<body>
<form>
<fieldset id="top">
<button id="clickme">click me</button>
</fieldset>
<fieldset id="bottom">
</fieldset>
</form>
<script src="test.js"></script>
</body>
</html>
test.html
调用test.js
:
console.log("checking in");
document.getElementById("clickme").onclick = function () {
var newButton = document.createElement("button");
newButton.textContent = "now click me";
newButton.onclick = function () {
document.getElementById("bottom").style.backgroundColor = "pink";
};
document.getElementById("bottom").appendChild(newButton);
alert("I'm an alert. If you comment me out, the tab will revert to its unmodified state, probably before you even see the second button.");
};
新按钮出现,但一旦警报被清除就会消失。我发现对扩展中打开的选项卡或弹出窗口所做的DOM修改总是在脚本完成后立即恢复到原始状态。有办法让其中一个不动吗?
您的<form>
在点击时重新提交,在没有操作url的情况下,它只是重新加载页面。
要么根本不使用<form>
,要么使用适当的onsubmit事件侦听器,要么在所有单击侦听器中添加event.preventDefault();
,要么将type="button"
添加到所有按钮中。
相关文章:
- 当包含另一个asp文件时,是否也包含所有引用的样式和脚本页面
- 借助asp.net验证或java脚本对多个文本进行验证
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- Java脚本时间添加
- 不显示带有本地json文件数据的谷歌地图脚本
- JQuery添加元素需要在我的js之前再次添加JQuery脚本
- 从远程脚本获取用户IP
- 如何根据时间运行不同的脚本
- 如何将字符串值从php页面发送到java脚本页面
- 使用谷歌应用程序脚本将服务器端数据表返回到客户端
- 可以设置“;文件名"发生错误时显示的内联脚本标记的
- 当脚本由system.js加载时,如何要求('electron')
- HTML标记在脚本标记中工作
- 是否可以控制获取哪些Google地图脚本(JavaScript API)
- 使用谷歌应用程序脚本从工作表中获取值并将其显示在文本框中
- 显示时间的脚本
- ng应用程序使脚本无限运行
- 如何在运行时在angular 2中加载外部js脚本
- 正在查找此撤消脚本的存储库和文档
- DOM修改弹出窗口或标签在chrome扩展立即撤消一旦脚本完成