tags:

views:

30

answers:

3

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"&gt;
</body>
</html>
A: 

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"&gt;&lt;img style="border: medium none ;" id="buy_button_image" src="http://www.pumaskills.com/images/redgetaccessnow-vip.png"&gt;&lt;/a&gt;
</body>
</html>
Luke Schafer
that will work but the anchor tag would still be "visible" in the page. Someone could accidentally click it or select it.
Cfreak
@Cfreak - not if the anchor tag is set to display none and the image is inside - see my answer.
Peter Ajtai
@Peter that's not what his solution shows. His a tag has no id attached
Cfreak
@Cfreak - Exactly. I am suggesting something else, which is attaching the ID to the `A` tag and setting the visibility of the `A` tag to `none`.
Peter Ajtai
@Cfreak and @Peter - yeah sure, those are better solutions. I didn't spend, well, any time on it because it shows 5 seconds after page load, and I'm sure he would learn better by figuring out that by himself. However, you are both absolutely right.
Luke Schafer
+1  A: 

Change this:

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

To:

<div id="buy_button_image"><a href="http://google.com/"&gt;&lt;img style="border: medium none ;" id="buy_button_image" src="http://www.pumaskills.com/images/redgetaccessnow-vip.png"&gt;&lt;/a&gt;&lt;/div&gt;
Cfreak
Why do you need to wrap the `a` tag in a `div`? Seems superfluous.
Peter Ajtai
@peter you don't have to, I like to do it because then you are explicitly hiding all the elements in the div. It makes it easier to then go back and make changes later. For instance someone wants some other element or text that shouldn't be linked but should still display the same way as the button.
Cfreak
+1  A: 

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"&gt;
    </a>
</body>
</html>​​​​​​​​​​​​​​

Try it out with this jsFiddle

Peter Ajtai
Thank you Peter. This worked perfectly. I appreciate the help from everyone!
Yemi Ogunbase
@Yemi - Glad to hear it ;) Don't forget to accept my answer if it solved your problem (check mark outline right below the votes of an answer).
Peter Ajtai