[英]Chrome Extension Injected Javascript Button Changes Page
So, I am working on an extension that will scoop up the values in some text fields on a page, and search them on another site to make sure they are not trademarked. 因此,我正在开发一个扩展程序,该扩展程序将在页面上某些文本字段中获取值,并在另一个站点上搜索它们以确保它们没有商标。
I have injected a button in the page, and when I click it, it works, but it also boots me out to the main page of the site, as though I were not logged in. However, I am still logged in and can hit "back" to get back to where I was, but then all my text fields are no longer filled in. This is obviously a problem for the end user. 我在页面中注入了一个按钮,当我单击它时,它可以工作,但是它也将我引导到网站的主页,好像我没有登录。但是,我仍然登录并且可以点击单击“返回”回到我原来的位置,但随后我的所有文本字段都不再填写。这对于最终用户来说显然是个问题。
Any ideas? 有任何想法吗?
Here is my Content Script: 这是我的内容脚本:
window.addEventListener("load", function load(event){
var amz = document.getElementById("draft-field");
var TMbutton = document.createElement("button");
var text = document.createTextNode("TMHunt Your Product");
TMbutton.className = "a-button a-button-primary scripter-button button-fill"
TMbutton.appendChild(text);
amz.appendChild(TMbutton);
},false);
TMbutton.onclick = function() {
chrome.runtime.sendMessage("test");
}
This does create the button and has the desired effect, except for this side-effect of popping us into a different page. 确实会创建按钮并具有所需的效果,除了将我们弹出到其他页面的副作用之外。 Would this be something to do with the host page receiving a message to do something from my Javascript somehow that I am not seeing? 这与主机页面收到一条消息有关我的Javascript无法执行某件事的消息有关吗?
The button default type is submit
. 按钮的默认类型为submit
。 You should set the type to button
so it won't trigger the form submit action. 您应该将类型设置为button
以免触发表单提交操作。
window.addEventListener("load", function load(event){
var amz = document.getElementById("draft-field");
var TMbutton = document.createElement("button");
var text = document.createTextNode("TMHunt Your Product");
TMbutton.className = "a-button a-button-primary scripter-button button-fill";
TMbutton.type = "button";
TMbutton.appendChild(text);
amz.appendChild(TMbutton);
},false);
TMbutton.onclick = function() {
chrome.runtime.sendMessage("test");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.