开发者

Calling href from JavaScript

开发者 https://www.devze.com 2022-12-12 11:40 出处:网络
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 h开发者_StackOverflow中文版ref link and, after fi

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 h开发者_StackOverflow中文版ref 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.


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

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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消