Javascript not running from address bar

Go To StackoverFlow.com

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 ?

2012-04-03 20:26
by johngreen
Wouldn't it be easier for all parties if there was just a button that ran this - James Hay 2012-04-03 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. : - johngreen 2012-04-04 01:03
possible duplicate of Firefox 6 javascript in addressbarWladimir Palant 2012-05-26 08:35


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.

2012-04-03 20:29
by Jonathan Protzenko
Thanks ! It saved a lot of time - johngreen 2012-04-04 01:02