Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用chrome扩展将运行JavaScript函数的链接注入网站_Javascript_Html_Google Chrome_Google Chrome Extension_Code Injection - Fatal编程技术网

使用chrome扩展将运行JavaScript函数的链接注入网站

使用chrome扩展将运行JavaScript函数的链接注入网站,javascript,html,google-chrome,google-chrome-extension,code-injection,Javascript,Html,Google Chrome,Google Chrome Extension,Code Injection,我想在这个网页的末尾插入一个链接 链接将从一条记录循环到另一条记录,在链接末尾添加+1,因此当单击下一步时,链接将从http://lcsyndicate.com.lb/web/popupGuide.aspx?Guide_Id=5425至http://lcsyndicate.com.lb/web/popupGuide.aspx?Guide_Id=5426等 为此,我创建了一个带有iframe的HTML页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.

我想在这个网页的末尾插入一个链接 链接将从一条记录循环到另一条记录,在链接末尾添加+1,因此当单击下一步时,链接将从
http://lcsyndicate.com.lb/web/popupGuide.aspx?Guide_Id=5425
http://lcsyndicate.com.lb/web/popupGuide.aspx?Guide_Id=5426

为此,我创建了一个带有iframe的HTML页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>

</title><link href="includes/ls.css" rel="stylesheet" type="text/css" /></head>
<body bgcolor="#373536" >
<iframe 
 src="http://lcsyndicate.com.lb/web/popupGuide.aspx?Guide_Id=5425"
 width="100%" height="500"
 sandbox>
  <p>
    <a href="http://lcsyndicate.com.lb/web/popupGuide.aspx?Guide_Id=5425">
      Fallback link for browsers that, unlikely, don't support frames
    </a>
  </p>


</body>
</html>
My inject.js代码:

chrome.extension.sendMessage({}, function(response) {
    var readyStateCheckInterval = setInterval(function() {
    if (document.readyState === "complete") {
        clearInterval(readyStateCheckInterval);

        // ----------------------------------------------------------
        // This part of the script triggers when page is done loading
        console.log("Hello. This message was sent from scripts/inject.js");
        // ----------------------------------------------------------

    }
    }, 10);
});

var c=5425;
var url="http://lcsyndicate.com.lb/web/popupGuide.aspx?Guide_Id=";

function f(){ 
 document.getElementById("clicks").data = url+c;
 c++;
 }

var newlink = document.createElement('a');
newlink.innerHTML = 'Next>';
newlink.setAttribute('id','clicks');
newlink.setAttribute('title', 'Next>');
newlink.onclick = f;
newlink.setAttribute('onclick',"f()");
document.body.appendChild(newlink); 
然而,当扩展运行时,我在页面上得到一个“uncaughtreferenceerror:f未定义”错误

我不知道如何修理它。我只想添加一个从一个记录循环到另一个记录的链接


感谢任何帮助

谁提出了此错误?页面或注入的内容脚本?我认为的页面:
Uncaught ReferenceError:f未在click@popupGuide.aspx?Guide_Id=5425:1定义
尝试使用addListner而不是将事件处理程序放在onclick属性上?我添加了
newlink.addEventListener(“单击”,“f()”)错误已消失,但链接不起作用…这更像是
newLink.addEventListener(“单击”,f)
谁引发了此错误?页面或注入的内容脚本?我认为的页面:
Uncaught ReferenceError:f未在click@popupGuide.aspx?Guide_Id=5425:1定义
尝试使用addListner而不是将事件处理程序放在onclick属性上?我添加了
newlink.addEventListener(“单击”,“f()”)错误已消失,但链接不起作用…更像是
newLink.addEventListener(“单击”,f)
chrome.extension.sendMessage({}, function(response) {
    var readyStateCheckInterval = setInterval(function() {
    if (document.readyState === "complete") {
        clearInterval(readyStateCheckInterval);

        // ----------------------------------------------------------
        // This part of the script triggers when page is done loading
        console.log("Hello. This message was sent from scripts/inject.js");
        // ----------------------------------------------------------

    }
    }, 10);
});

var c=5425;
var url="http://lcsyndicate.com.lb/web/popupGuide.aspx?Guide_Id=";

function f(){ 
 document.getElementById("clicks").data = url+c;
 c++;
 }

var newlink = document.createElement('a');
newlink.innerHTML = 'Next>';
newlink.setAttribute('id','clicks');
newlink.setAttribute('title', 'Next>');
newlink.onclick = f;
newlink.setAttribute('onclick',"f()");
document.body.appendChild(newlink);