Solved

Creating a delayed link display in Javascript

Posted on 2006-11-30
4
451 Views
Last Modified: 2008-01-09
Hello folks,

I searched the Internet and have had no luck finding a Javascript that will allow me to delay the display of a link.

There are plenty of great delayed links, such as this one:

<head>
<script language="JavaScript">
<!--
var sTargetURL = "http://www.target page.com/index.html";

function doRedirect()
{ setTimeout( "timedRedirect()", 40*1000 ); }

// There are two definitions of 'timedRedirect', this
// one adds to the visitors page history.
function timedRedirect()
{
window.location.href = sTargetURL;
}
//-->
</script>
<script language="JavaScript1.1">
<!--
function timedRedirect()
{ window.location.replace( sTargetURL ); }
//-->
</script>
</head>

<body>
  <p align="center" class="style2">
<a href="javascript:doRedirect()">Continue to Website</a>

But I am not interested on a delay after the link is displayed. Rather, I want to delay the *displaying* of the text, "Continue to Website."

There are two possible ways to do this...
1 - make the text (link) appear invisable (same as background color) and change it to a different color after a preset amount of time
OR
2 - actually hold back the display of the text (link) until a preset amount of time has past.

I will offer an additional 125 pts for both methods.

How can I accomplish this task?

Thank you.
0
Comment
Question by:sconnell
  • 2
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
devic earned 250 total points
ID: 18047010

here check some methods:
//============================================================================
<html>
<body bgcolor="white">

<div id="myLink1">&nbsp;</div>
<a id="myLink2" style="display:none" href="http://www.yahoo.com">yahoo</a><br>
<a id="myLink3" style="color:white;" href="http://www.answers.com">answers</a><br>

<script>
setTimeout("inserLink()", 1000);
setTimeout("displayLink()", 2000);
setTimeout("colorLink()", 3000);
setTimeout("appendLink()", 4000);


function inserLink()
{
      document.getElementById("myLink1").innerHTML = "<a href='http://www.msn.com'>msn</a>";
}

function displayLink()
{
      document.getElementById("myLink2").style.display = "inline";
}

function colorLink()
{
      document.getElementById("myLink3").style.color = "blue";
}

function appendLink()
{
      var aLink = document.createElement("a");
      aLink.href = "http://www.google.com";
      aLink.innerHTML = "<b>google</b>";
      document.body.appendChild(aLink);
}
</script>


</body>
</html>
0
 
LVL 4

Author Comment

by:sconnell
ID: 18049072
Fantastic!

This is exactly what I am looking for!

Can you please tell me how to get the "aLink.innerHTML = "<b>google</b>";"  to center on the webpage (rather than default to left justified).

Thank you again!
0
 
LVL 25

Expert Comment

by:devic
ID: 18050424
simple add <center> tag:
=======================================
<html>
<body bgcolor="white">

<script>
setTimeout("appendLink()", 2000);


function appendLink()
{
     var aLink = document.createElement("a");
     aLink.href = "http://www.google.com";
     aLink.innerHTML = "<center><b>google</b></center>";
     document.body.appendChild(aLink);
}
</script>


</body>
</html>
0
 
LVL 4

Author Comment

by:sconnell
ID: 18050659
DOH! I think I need some sleep!

Thank you!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now