最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Calling href from JavaScript - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question edited Dec 18, 2016 at 7:14 user6269864 asked Nov 23, 2009 at 11:27 DancingSheepDancingSheep 111 gold badge1 silver badge2 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 11

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)

  1. 暂无评论