JavaScript href call

This is the same question as THIS IS ONE , I can no longer answer this question, so I am rewriting it using my account. Sorry for the mess.

I need a Greasemonkey script that activates a href link on a page load, such as "javascript: FUNCTION". I saw 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 although it works on a local page even when using onload, it does not work when I use it in a script.

I probably miss something while passing code from the body of an html page to a Greasemonkey script.

Hope this time the question is clearer, excuse me for any misunderstanding, but I'm still new to JS.

+7
javascript href greasemonkey hyperlink
source share
3 answers

Solved this as follows:

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

Thanks everyone for the answer anyway.

+17
source share
 <script type="text/javascript"> function somescript() { eval(document.getElementById('ololo').getAttribute('href').replace('javascript:', '')); } </script> 

I see a warning window.

Please note that this will only work when its javascript is in the href attribute ...

+4
source share

Will this work for your scenario?

 <script type="text/javascript"> function somescript() { document.getElementById('ololo').click();//fake a click on the link } </script> 
0
source share

All Articles