0

I'm trying to combine the functionality of the 3 codes below to produce a delayed redirect to a random URL while displaying a bar filling up by %. Each one works great, but I need all 3. Any help would be greatly appreciated. Thanks!

The first redirects after a delay

<script type="text/JavaScript">
<!--
setTimeout("location.href = 'http://www.yourURL.com';",1500);
-->
</script>

The second redirects to a random URL

<script type="text/javascript">
(function(n){
 var pages = ['http://www.thestormybrain.com/2013/11/malcolm-gladwell-choice-happiness-and.html', 'http://www.thestormybrain.com/2013/11/steve-jobs-how-to-live-before-you-die.html', 'http://www.thestormybrain.com/2013/11/david-blaine-how-i-held-my-breath-for.html'];
 n = n < 3? 0 : n < 8? 1 : 2;
 window.location.replace(pages[n]);
})(Math.floor(Math.random() * 10));
</script>

The third redirects using a bar being filled with %

<style>

* { font-family: "Arial", sans-serif; }

#wrap { margin-top: 50px;text-align: center; }

#barwrap { 
position: relative; /* to contain outer */ 
margin: 0 auto; /* to centre */ 
width: 500px;height: 20px; /* size of our bar - required */ 
text-align: left; 
font-weight: bold; 
border: 1px solid black; 
}

#barwrap P { /* to contain text */ 
margin: 0; /* FF needs this or text drops below bar */ 
width: 500px; /* use this node to position text */ 
text-align: center; 
}

#barwrap #outer { /* bar 'background' */ 
position: absolute; 
width: 100%; height: 100%; /* match parent size */ 
background: gray; 
color: #330000; /* original colour of text */ 
}

#barwrap #inner { 
position: relative; /* otherwise outer hides us */ 
width: 0; height: 100%; /* match parent */ 
overflow: hidden; /* to hide new text/prevent it wrapping */ 
background: black; 
color: #ff0000; /* colour of changed text */ 
}

</style>

<script>

var time = 10000; // 10 secs 
var steps = 50; // Five per second 
var step = 1;

function progress() { 
var bar = document.getElementById( "barwrap"); 
var aStep = (bar.offsetWidth -2) /steps;// 2px border removed from width 
var x = Math.round( aStep *step); 
var outer = document.getElementById( "outer"); 
var inner = document.getElementById( "inner");

// Work out seconds based on % progress from current step 
var secs = (( time /1000) -Math.floor( ( step /steps) *10));

inner.style.width = x +"px"; 
step++;

// If 0 seconds, display waiting message instead 
outer.firstChild.innerHTML = ( secs? secs +" seconds...": "Please Wait..."); 
// Match text 
inner.firstChild.innerHTML = outer.firstChild.innerHTML;

if( step <= steps) setTimeout( "progress();", time /steps); 

window.location = 'http://YourDomainName.com'; 
}


</script> 


<div id='wrap'> 
Finding you the perfect article. Hold tight... 
<div id='barwrap'> <!-- P wrappers for text positioning --> 
<div id='outer'><p></p></div> <!-- original colour/text --> 
<div id='inner'><p></p></div> <!-- new colour/text --> 
</div>

<br> 
<body onload="progress();">

</div>
4
Contributors
22
Replies
83
Views
3 Years
Discussion Span
Last Post by happygeek
Featured Replies
  • I'm not frustrated at all. Sorry if my double post made it appear that way. I just read that questions with donations get answered more often, so I thought I did it the wrong way. And I kinda felt like a jerk for not pressing the donation button in the … Read More

  • 1

    I'm sure Dani is appreciative of your donation and maybe someone can help here.. Just to clarify, your objective is to redirect the user to a random (1 of 3) page after 10 seconds of landing on this page, while showing a progress bar? Read More

  • 1

    Sounds interesting. I'll take a look at your code tomorrow. If I can add value i'll post some ideas. If not, someone else may help. Read More

  • Not sure how I offended you, but I heavily apologize. I'm truly sorry for posting twice, and I'm sorry for donating to the site. I'll just assume you're having a really bad day, and that you don't mean to be so confrontational. Please don't call me any more names, by … Read More

  • 1

    Gentlemen, I'll ask that we put whatever has happened in the past and move from this point on. You are both valued members, I beleive this was all a misunderstanding. We are all here to collaborate and learn from each other. Thank you. Read More

0

I wasn't helped with the first, but found some extra info in the meantime. I was going to merely edit the first instead, but thought the lack of response was due to my lack of donation. So I opted to post again in order to donate to this great site. If no one knows the answer, it's ok. I've received more than my share of help from all of you. Thanks.

-2

I was going to merely edit the first instead, but thought the lack of response was due to my lack of donation. So I opted to post again in order to donate to this great site. If no one knows the answer, it's ok. I've received more than my share of help from all of you.

@jonsan32

I think you need to understand something just because you donate money to Daniweb doesn't necessary mean someone will help you immediately with your issue. It doesn't go like that.

It's freewill.

My impression is that you donate money to become a Sponsor to Daniweb & a Daniweb member can help with your code.

Right now, you are frustrated that noone is helping you?

I can tell you that I treat all members the same regardless whether that member donate or not.

Didn't you have Airshow helping you offline before? Ask him again. I saw him online a few times now.

Right now what you said something rub me the wrong way.

Edited by LastMitch

1

I'm not frustrated at all. Sorry if my double post made it appear that way. I just read that questions with donations get answered more often, so I thought I did it the wrong way. And I kinda felt like a jerk for not pressing the donation button in the first place, so when I gained the new info I took that opportunity to repost and add the donation.

If no one can help, no one can help. It's absolutely OK. Seriously. I love Daniweb, and just wanted to help in keeping it an online force. Have a great day. I'll try my question in another forum.

1

I'm sure Dani is appreciative of your donation and maybe someone can help here..

Just to clarify, your objective is to redirect the user to a random (1 of 3) page after 10 seconds of landing on this page, while showing a progress bar?

1

Sounds interesting. I'll take a look at your code tomorrow. If I can add value i'll post some ideas. If not, someone else may help.

Edited by JorgeM

-5

I'm not frustrated at all. Sorry if my double post made it appear that way. I just read that questions with donations get answered more often, so I thought I did it the wrong way. And I kinda felt like a jerk for not pressing the donation button in the first place, so when I gained the new info I took that opportunity to repost and add the donation.

If no one can help, no one can help. It's absolutely OK. Seriously. I love Daniweb, and just wanted to help in keeping it an online force. Have a great day. I'll try my question in another forum.

@jonsan32

You know you are being jerk now. Why you keep mention donations? This has nothing to do with donations, you just want someone to figure out / do the code for you just because you donated money to Daniweb.

You know you are abusing this privileged of becoming a Sponsor.

I help you in the past more than a couple times.

I'm pretty sure I remember that you had a thread posted more than 5 months old and noone bother even answering that thread. I answered that thread. You never say something like before?

I can tell you that I treat all members the same regardless whether that member donate or not.

I can tell you right now, you are the only Sponsor member who said something like this, thinking you are entitle to get your code writing for you.

I'll try my question in another forum.

I doubt someone will answer that question over the other forums.

1

Not sure how I offended you, but I heavily apologize. I'm truly sorry for posting twice, and I'm sorry for donating to the site. I'll just assume you're having a really bad day, and that you don't mean to be so confrontational.

Please don't call me any more names, by the way.

Have a great night. Sorry again.

Votes + Comments
Stop being a jerk!
0

PS About the donation thing... I was referencing the following statement. So I didn't just make it up; and I thought I was just playing by the rules presented to me. I didn't mind. It was just stated.

Donate $1 to DaniWeb and receive a featured priority listing
You will receive better, quicker replies because featured discussions receive 1000% more views on average. You will be redirected to PayPal upon submitting your post to make a donation of any amount of your choosing, and, upon completion, you'll be taken to your newly featured discussion.

-3

Not sure how I offended you, but I heavily apologize. I'm truly sorry for posting twice, and I'm sorry for donating to the site. I'll just assume you're having a really bad day, and that you don't mean to be so confrontational.

Please don't call me any more names, by the way.

Have a great night. Sorry again.

@jonsan32

Oh you are getting sensitive now. I'm not having a bad day you are.

0

I reviewed your code and did some testing and put some snippets of code together and came up with this example... feel free to test it, add your own code, see if it works out for you.

<!DOCTYPE html>
<html>
<head>
 <title>Demo</title>
<style>
#progressBar {width: 400px;height: 22px;border: 1px solid #7f7f7f;}
#progressBar div {height: 100%;width: 0px;background-color: #aa00ff;}
</style>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
 </script>
</head>
<body>
Redirecting you in <span id="countdown">10</span> seconds
<div id="progressBar"><div></div></div>
<script>
var sec = 10;
var pages = ['http://www.thestormybrain.com/2013/11/malcolm-gladwell-choice-happiness-and.html', 'http://www.thestormybrain.com/2013/11/steve-jobs-how-to-live-before-you-die.html', 'http://www.thestormybrain.com/2013/11/david-blaine-how-i-held-my-breath-for.html'];

progress(); 
countDown(); 


function progress() {
  var progressBarWidth = $('#progressBar').width();
 $('#progressBar div').animate({ width: progressBarWidth }, 10000);
}

function countDown() {
  if (sec < 10) {
    $('#countdown').html("0" + sec);
  } else {
    $('#countdown').html(sec);
  }
  if (sec <= 0) {
    redirect();    
  }
  sec -= 1;
  setTimeout(countDown, 1000);
}

function redirect() {
var n = Math.floor(Math.random() * 3)
window.location = pages[n];
}

</script>

</body>
</html>

Take a look at a working sample... >> http://itg.somee.com/dw/dw-467181

Edited by JorgeM

0

@jonsan32

Can you refrain yourself from downvoting?

1

Gentlemen, I'll ask that we put whatever has happened in the past and move from this point on. You are both valued members, I beleive this was all a misunderstanding.

We are all here to collaborate and learn from each other.

Thank you.

0

Gentlemen, I'll ask that we put whatever has happened in the past and move from this point on. You are both valued members, I beleive this was all a misunderstanding.

@JorgeM

If I was a valve member why you downvoted me? Nice work!

0

I honestly do believe you are a valued member. You've helped many people here. I have no hard feelings for anyone on DaniWeb.

With regard to the votes, as a moderator, I couldn't tell you who voted because that information is not available to me. If you contact an admistrator on this site, you may be able to get more information.

0

Even us admins have no idea who upvotes/downvotes. It is designed to be an anonymous voting system unless a member wants to add positive/negative reputation in which case a comment has to be left which identifies the member.

Anyway, I agree with Jorge; I'm not really sure what is going on in this thread and can only assume there has been a misunderstanding somewhere along the way. Making a donation is encourgaged as it helps us with the running costs of DaniWeb and, as it says when we offer members the donation option "You will receive better, quicker replies because featured discussions receive 1000% more views on average".

I'm happy that jonsan got his code sorted (nice one Jorge), happy that he donated (thanks jonsan) sorry that LastMitch feels bad (PM me if you have any outstanding concerns) but hopeful this can now be put to bed.

Edited by happygeek

0

11 downvotes?

Edited by LastMitch

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.