Hi, I have a problem with javascripting in Firefox for a little project to be used with the greasemonkey extension. I've been trying to get this to work all day long but no success so I hope someone can give me a solution.

What it needs to do is check the URL of the previous page (the caller), if the URL equals some text it has to go to the page that was before that, so it has to access the firefox history. I could just go back using "history.go(-2)" but I need to get there with the page refreshed and that's not the case using the "history.go" method. That's why I want to read the url from the FF history array and load it that way.
Keep in mind that I've only started learning javascript so if there are stupid things written, bear with me

Code:
var previous_page = document.referrer;    //read the url from the previous page
if(previous_page.indexOf("sometext") !=-1){     //if previous page url contains sometext
    if (history[2].indexOf("right") != -1) {     //check history array (2 pages ago) and check if "right" is in the url
        var x = "http://testdotcom/right";
    }else if (history[2].indexOf("left") != -1) {   //check history array (2 pages ago) and check if "left" is in the url
        var x = "http://testdotcom/left";
    }
}else { var x = previous page;         //sometext was not in the url of the previous page so use the url of previous page
}
window.location = x;                          //go to new url, being previous or second to previous
So the code loads the previous page (referrer) in a refreshed way, or loads the page before that from reading the history also refreshed.
I hope I made it as clear as possible and hope someone can help me out. I've only just started learning javascript for couple of days, it's been going decent so far, but sometimes the smallest things are holding you back
I'd be very grateful for some help with this piece of code!

TIA!