开发者

Question about hyperlinking a Javascript Object

I can make the button appear after 5 seconds. I'd like to be able to click the button and go to a different site (like google.com, for example). Help please?

<style type="text/css">

#buy_button_image { display: none; }

</style>

<script type="text/javascript">

window.onload = function()
{
var img = document.getElementById("buy_button_image");
var _t = function() {
    img.style.display = "block";
};
window.setTimeout(_t, 5000);
window.clearTimeout(_t);
};
</script>

</head>

<body>
<img style="border: medium none ;" id="buy_button_image" src="http://www.pumaskills.com/images/redgetaccessnow-vip.png">
</body>
<开发者_JS百科/html>


Change this:

<img style="border: medium none ;" id="buy_button_image" src="http://www.pumaskills.com/images/redgetaccessnow-vip.png">

To:

<div id="buy_button_image"><a href="http://google.com/"><img style="border: medium none ;" id="buy_button_image" src="http://www.pumaskills.com/images/redgetaccessnow-vip.png"></a></div>


Use an a tag:

Note that your clearTimeout does nothing. Take a look at the setTimeout() and clearTimeout() references.

<html>
<head>
<style type="text/css">    
    #buy_button_image { display: none; }
</style>

<script type="text/javascript">
window.onload = function()
{
    var img = document.getElementById("buy_button_image");
    var _t = function() {
        img.style.display = "block";
    };
    window.setTimeout(_t, 5000);
};
</script>

</head>

<body>
    <a href="http://www.pumaskills.com" id="buy_button_image">
        <img style="border: medium none ;" src="http://www.pumaskills.com/images/redgetaccessnow-vip.png">
    </a>
</body>
</html>​​​​​​​​​​​​​​

Try it out with this jsFiddle


Anchor tag?

<style type="text/css">

#buy_button_image { display: none; }

</style>

<script type="text/javascript">

window.onload = function()
{
var img = document.getElementById("buy_button_image");
var _t = function() {
    img.style.display = "block";
};
window.setTimeout(_t, 5000);
window.clearTimeout(_t);
};
</script>

</head>

<body>
<a href="http://www.stackoverflow.com"><img style="border: medium none ;" id="buy_button_image" src="http://www.pumaskills.com/images/redgetaccessnow-vip.png"></a>
</body>
</html>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜