我怎样才能让一个Chrome扩展自动点击一个按钮时

我怎样才能让一个Chrome扩展自动点击一个按钮时

本文介绍了我怎样才能让一个Chrome扩展自动点击一个按钮时,页面加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个谷歌Chrome扩展程序,presses页面加载一个按钮。我已经能够使用该code触发使用VBScript Internet Explorer的按钮:

I'm trying to create a Google Chrome extension that presses a button on page load. I've been able to trigger the button using VBscript for Internet Explorer by using this code:

IE.Navigate("javascript:changeIframe();")

不过,现在我需要通过一个扩展做谷歌浏览器。但是,按钮没有一个id:

But, now I need to do it in Google Chrome via an extension. However, the button does not have an id:

<input type="button" value="Start!" onclick="javascript:changeIframe();">

和这里就是我试过到目前为止并没有什么似乎工作:

and here's what I've tried so far and nothing seems to work:

window.onload="javascript:changeIframe()";
javascript:changeIframe();
document.getElementById('').click();
document.getElementById('').submit();

似乎。点击 .submit 不是在谷歌,Chrome的JavaScript的定义?

It seems that .click and .submit is not defined in Google-Chrome's javascript?

奇怪的是,当我使用这个脚本:

The weird thing is that when I use this script:

javascript:changeIframe();

在Chrome的JavaScript控制台,它$ P $自动psses按钮,一切工作正常。但是,当我把同样的剧本在我的js文件这是行不通的。

in Chrome's javascript console, it presses the button automatically and everything works fine. But, when I put the same script in my .js file it does not work.

我只需要知道我有什么可以自动把我的.js文件内以preSS按钮在页面加载。

I just need to know what I have to put inside my .js in order to press the button automatically on page load.

推荐答案

传统的方式做,这是的注入的的code :

The traditional way to do this is to inject the code:

var scriptNode          = document.createElement ('script');
scriptNode.textContent  = 'changeIframe ();';

document.body.appendChild (scriptNode);

结果
你将通常没有侦听的onload 无论是作为内容脚本将在该点在默认情况下大约火。


You won't normally have to listen for onload either, as content scripts will fire roughly at that point by default.

搜索结果

扩展JS在一个孤立的世界工作,并与页面的JavaScript没有不在这里需要一些技巧,无法进行互动。

The extension JS operates in an "Isolated World" and cannot interact with the page's javascript without some tricks that are not needed here.

这篇关于我怎样才能让一个Chrome扩展自动点击一个按钮时,页面加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 19:23