Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call href from JavaScript

This is the same question as THIS ONE, I can't answer that anymore, so I'm re-posting it with my account.
Sorry for the mess.

I need a Greasemonkey script that on a page load activates a href link like 'javascript:FUNCTION'. I've seen this code:

<script language="Javascript" type="text/javascript">
    function somescript() {
            window.location.href = document.getElementById('ololo').href;
    }
</script>

<a href="javascript:alert('test');" id="ololo">test</a>
<br />

<a href="javascript:somescript()">click me</a>

and, while it works on a local page even when using onload, it doesn't work when I use it in my script.

Probably I'm missing something when transferring the code from the body of an html page to a Greasemonkey script.

I hope this time the question is more clear, excuse me for any misunderstanding, but I'm still a beginner with JS.

like image 517
Gurzo Avatar asked Nov 23 '09 13:11

Gurzo


1 Answers

Solved it like this:

window.location=document.getElementById('foo').href;

Thanks everyone for answering anyway.

like image 117
Gurzo Avatar answered Oct 25 '22 08:10

Gurzo