DancingSheep
DancingSheep

Reputation: 11

Calling href from JavaScript

I'm developing a script for Greasemonkey, but I'm stuck trying to activate links via JavaScript.

The script should check the web page for a certain href link and, after finding it, it must activate it (like clicking on the link).

If it helps, the href I'd like to activate is a "javascript:FUNCTION" kind of link.

Upvotes: 1

Views: 30426

Answers (3)

vsr
vsr

Reputation: 3198

For functionalities like these where an onclick has to be fired on elements, I find it easy and fast to use jquery. If you can include jquery, then you can use the click() function on that element.

Upvotes: -1

silent
silent

Reputation: 3923

<html>
<body>
    <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>

</body>
</html>

Upvotes: 4

Yacoby
Yacoby

Reputation: 55465

Find the url that you want to direct the user to and then use

var href = ...//find url
window.location=href;

Upvotes: 11

Related Questions