Adding javascript to hyperlink - Stack Overflow

How can i add a Javascript alert to the hyperlink ?I want to make the alert pop up when someone click

How can i add a Javascript alert to the hyperlink ? I want to make the alert pop up when someone click on the link . This is the script for now -

<a href="<?php echo ($link1);?>" onclick="popitup();" data-role="button" data-theme="b" data-inline="true" > Send </a>

And i want to add this to the link

<script type="text/javascript">alert('Text.');</script>

How can i add a Javascript alert to the hyperlink ? I want to make the alert pop up when someone click on the link . This is the script for now -

<a href="<?php echo ($link1);?>" onclick="popitup();" data-role="button" data-theme="b" data-inline="true" > Send </a>

And i want to add this to the link

<script type="text/javascript">alert('Text.');</script>
Share Improve this question asked Oct 9, 2012 at 8:03 Ido BukinIdo Bukin 511 gold badge2 silver badges6 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 2

You should define the popitup() function that you are calling in your onclick attribute:

<script type="text/javascript">
    function popitup() {
        alert('Text.');
    }
</script>

also if you want to prevent the link from redirecting under certain conditions you could return false from this handler:

<a href="<?php echo ($link1);?>" onclick="return popitup();" data-role="button" data-theme="b" data-inline="true"> Send </a>

and then:

<script type="text/javascript">
    function popitup() {
        if (confirm('Are you sure you want to do that?')) {
            return true;
        }
        return false;
    }
</script>

if the alert should do some kind of logic you can use the return function like this

<a href="newlink.html" onClick="return confirm('do you really wanna go to this link?')" >the link</a>

or just add the alert w/o any logic in this way

<a href="newlink.html" onClick="alert('you are going to the link! beware!')" >the link</a>

Try this

<a href="new.html" onclick="alert('This is going to link')"> link </a>

You can add javascript statements to a href attribute by putting javascript: before the statement, so it would be something like:

<a href="javascript: alert('Text.');" ></a>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745326004a4622658.html

相关推荐

  • Adding javascript to hyperlink - Stack Overflow

    How can i add a Javascript alert to the hyperlink ?I want to make the alert pop up when someone click

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信