简体   繁体   English

Chrome扩展程序注入了Javascript按钮更改页面

[英]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.

相关问题 Chrome 扩展:注入按钮的 onclick 不起作用 - Chrome Extension: Injected button's onclick not working 从Chrome扩展程序注入的脚本可以访问页面上的javascript(angularjs)吗? - Do injected script from Chrome Extension have access to javascript (angularjs) on the page? 从 web 页面按钮点击调用 Chrome 扩展中的 JavaScript 方法 - Call JavaScript method in Chrome extension from web page button click 如何让 Chrome 扩展按钮与注入的 js 通信? - How to have chrome extension button communicate with injected js? 从Chrome扩展程序AJAX加载的页面运行注入的JS函数 - Running injected JS functions from a Chrome extension AJAX loaded page Chrome扩展程序:注入到给定页面后更改iframe源内容 - Chrome Extension : changing iframe source content after injected to a given page 从以编程方式注入的 Chrome 扩展程序中的弹出窗口链接到选项页面 - Link to options page from popup in programatically injected Chrome extension 注入 Javascript 的 Chrome 扩展 - 无法读取未定义的属性(读取“sendMessage”) - Chrome Extension with injected Javascript - Cannot read properties of undefined (reading 'sendMessage') 刷新页面,直到它更改 chrome 扩展 - refresh page until it changes chrome extension Chrome扩展程序-更改网址后附加到页面 - Chrome Extension - Append to page when url changes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM