简体   繁体   English

从谷歌浏览器扩展调用页面功能

[英]Invoke a page function frome google chrome extension

As a beginner, I am sorry to say that I don't know how to invoke a function which is defined in webpage index.html from a google chrome extension.作为初学者,我很遗憾地说我不知道​​如何从谷歌浏览器扩展程序调用在网页 index.html 中定义的函数。

I want to change two fields in the page i am able to change one textbox field, the second one is a selection box and there is a jquery function to be invoked to add items in selection box.Is it possible to invoke it from my extension.我想更改页面中的两个字段我可以更改一个文本框字段,第二个是选择框,并且有一个 jquery 函数可以调用以在选择框中添加项目。是否可以从我的扩展程序中调用它.

My manifest file我的清单文件

{
  "name": "My First Extension",
  "version": "1.0",
  "manifest_version": 2,
  "description": "The first extension that I made.",
  "browser_action": {
    "default_icon": "icon.png"
  },
  "permissions": [
      "tabs", "https://*/*"
    ],
    "content_scripts": [
      {
        "matches": ["https://*/*"],
        "js": ["jquery-1.7.2.min.js","content.js"],
        "run_at": "document_end"
      }
  ]
}

My content.js我的 content.js

var subdist = document.getElementById('ContentPlace');

subdist.value="5673";

Webpage : index.php网页:index.php

The function to be invoked to update the selection box is :要调用以更新选择框的函数是:

onchange="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolderMainContent$DropDownVillage\',\'\')', 0)"

Referred to: Chrome call function in content scripts from background.js参考: 来自 background.js 的内容脚本中的 Chrome 调用函数

Calling Content Script function on chrome.browserAction.onClicked 在 chrome.browserAction.onClicked 上调用内容脚本函数

With a content script you can inject a script tag into the DOM in order to access variables and functions in the original page as explained here随着内容的脚本可以解释为在原始页面,以便注入的脚本标记到DOM访问的变量和函数在这里

Like :喜欢 :

var script = document.createElement("script");
script.type="text/javascript";
script.innerHTML = "window.pageFunction(args);"
document.body.appendChild(script);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM