A S A S - 1 year ago 78
Javascript Question

Vimperator and Javascript: getting value of an object

Let's say I've just open a random Stackoverflow page, then I open Console in Firefox and run something like this:


As a result, it will pop up me the question asked on that page (on this particular page it would be
Vimperator and Javascript: getting value of an object

Now, I want to use that value in a script with Vimperator. I add something like this to my

:js << EOF
function dummyFu() {
var myElement = document.getElementsByClassName("question-hyperlink");
map <F5> :js dummyFu()<CR>

However, when run, it says
TypeError: myElement[0] is undefined

So, what is wrong? Would be grateful for any suggestion, thanks.

Answer Source

See https://developer.mozilla.org/en-US/docs/Web/API/Window/content

E.g., content.document.getElementsByClassName("question-hyperlink")[0].firstChild.textContent;

(No, it's not me, but all the credits go to GitHub user dkearns, actually. Thanks them a lot. :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download