admin管理员组

文章数量:1391947

I want to run a javascript function from the browser console,
I'm trying to do it in Chrome (windows 7) and my function is this:

function playVideo() {
    var popo = document.getElementsByTagName("object");
      for (var i=0; i<popo.length; i++) {
        popo[i].playVideo(); 
      }
  }

normally this function works fine when I fire it from a webpage

<button onclick="playVideo();">play</button>

or

<a href="javascript:playVideo();">play</a>

but if I paste it into the browser console, and I press Return,
it doesn't work and there is this error:
"undefined"
.jpg

What i'm doing wrong?

I want to run a javascript function from the browser console,
I'm trying to do it in Chrome (windows 7) and my function is this:

function playVideo() {
    var popo = document.getElementsByTagName("object");
      for (var i=0; i<popo.length; i++) {
        popo[i].playVideo(); 
      }
  }

normally this function works fine when I fire it from a webpage

<button onclick="playVideo();">play</button>

or

<a href="javascript:playVideo();">play</a>

but if I paste it into the browser console, and I press Return,
it doesn't work and there is this error:
"undefined"
http://oi57.tinypic./z1hjc.jpg

What i'm doing wrong?

Share Improve this question asked Mar 22, 2014 at 23:33 user3443329user3443329 2
  • you just defined a function. Call it. – Benjamin Gruenbaum Commented Mar 22, 2014 at 23:39
  • I've tried to call it, but without success.. I don't understand why... – user3443329 Commented Mar 23, 2014 at 12:54
Add a ment  | 

1 Answer 1

Reset to default 1

After paste to console and pressing return you must call this function by name, in you case, after "undefined" write to consle "playVideo()" and press Return.

本文标签: chromerun javascript function from browser console quotundefinedquotStack Overflow