2

I have written the following Javascript code :

var outerFrame = document.getElementById("myframe");
    var outerDoc = outerFrame.contentDocument || outerFrame.contentWindow.document;
    var innerFrame = outerDoc.getElementsByName("frame").item(0);
    var innerDoc = innerFrame.contentDocument || innerFrame.contentWindow.document;
    var arr=[10,11,12,13,14,15,16,17,18,19,110,111,112,113,114,115,116,117,118,119]; 
    for(i=0;i<20;i++){
        var randomVal = Math.floor((Math.random()*5));
        if (innerDoc.getElementsByName("point"+arr[i])[randomVal]) {innerDoc.getElementsByName("point"+arr[i])[randomVal].checked = true; }
        }

I want people to be able to run it when on a particular website by copy-pasting it to the address bar. A little Google search tells me I need to append 'javascript:' before it. However, it does not work; nothing happens when I try to execute the code from the address bar. The code runs fine when I execute it from the console.

An error that comes up when trying to execute it from the address bar is :

uncaught exception: ReferenceError: document is not defined

Any help ?

3
  • Wouldn't it be easier for all parties if there was just a button that ran this? Commented Apr 3, 2012 at 20:42
  • Not really. I am trying to modify the DOM of a website for the user and so, putting a button is not in my hands. :) Commented Apr 4, 2012 at 1:03
  • possible duplicate of Firefox 6 javascript in addressbar Commented May 26, 2012 at 8:35

1 Answer 1

4

I'm pretty sure what you want is this question: Firefox 6 javascript in addressbar ; tl;dr Firefox (among others) won't allow you to run javascript snippets in the address bar anymore.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks ! It saved a lot of time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.