使用tampermonkey中的按钮切换HTML
我一直在尝试让脚本在切换按钮时切换一段HTML, 但到目前为止我还没能让它工作使用tampermonkey中的按钮切换HTML,html,tampermonkey,Html,Tampermonkey,我一直在尝试让脚本在切换按钮时切换一段HTML, 但到目前为止我还没能让它工作 let newImg5 = document.createElement("img"); newImg5.src = "https://www.pcinvasion.com/wp-content/uploads/2016/12/discord.jpg"; newImg5.style = `position: absolute; bottom: 15px; left: 15px; z-index: 100000; wi
let newImg5 = document.createElement("img");
newImg5.src = "https://www.pcinvasion.com/wp-content/uploads/2016/12/discord.jpg";
newImg5.style = `position: absolute; bottom: 15px; left: 15px; z-index: 100000; width: 50px; height: 50px; cursor: pointer;`;
document.body.prepend(newImg5);
newImg5.addEventListener("click", () => {
toggle.html <iframe src="https://discordapp.com/widget?id=68awdawdawdawds8&theme=dark" width="350" height="500" allowtransparency="true" frameborder="0"></iframe>
});
听起来你想做这样的事情:
let newImg5 = document.createElement("img");
newImg5.src = "https://www.pcinvasion.com/wp-content/uploads/2016/12/discord.jpg";
newImg5.style = `position: absolute; bottom: 15px; left: 15px; z-index: 100000; width: 50px; height: 50px; cursor: pointer;`;
document.body.prepend(newImg5);
/* create iframe */
let iframe = document.createElement('iframe');
iframe.setAttribute('id', 'iframe');
iframe.setAttribute('src', 'https://discordapp.com/widget?id=68awdawdawdawds8&theme=dark');
iframe.setAttribute('width', '350');
iframe.setAttribute('height', '500');
iframe.setAttribute('allowtransparency', 'true');
/* Make iframe appear on click */
newImg5.addEventListener("click", () => {
document.body.append(iframe);
});
toggle.html我知道,我正在努力找到一个可以工作的。看起来大多数片段都可以工作,但是现在iFrame没有出现,尝试了改变它的位置,它将附加html,但这也没有什么不同。