Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

Javascript timer not working

In the code below...
The timer is not waiting 7 seconds...
It is redirecting immediately
I need the delay

    <script type="text/javascript">
        window.onload = function () {
            var foo = 'http://members.mywebsite.com/gp.aspx?enc=' + getParameterByName('enc');
            //alert(foo);
            setTimeout("window.location='" + foo + "'", 7000);
        };
        
        function getParameterByName(name, url) {
            if (!url) url = window.location.href;
            name = name.replace(/[\[\]]/g, "\\$&");
            var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
                results = regex.exec(url);
            if (!results) return null;
            if (!results[2]) return '';
            return decodeURIComponent(results[2].replace(/\+/g, " "));
        }
    </script>

Open in new window

Avatar of HainKurt
HainKurt
Flag of Canada image

check this

window.onload = function() {
  var foo = 'http://members.mywebsite.com/gp.aspx?enc=' + getParameterByName('enc');
  alert(foo);
  setTimeout("window.location='" + foo + "'", 7000);
};

function getParameterByName(name, url) {
  if (!url) url = window.location.href;
  name = name.replace(/[\[\]]/g, "\\$&");
  var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
    results = regex.exec(url);
  if (!results) return null;
  if (!results[2]) return '';
  return decodeURIComponent(results[2].replace(/\+/g, " "));
}

Open in new window


https://jsfiddle.net/HainKurt/o5v22s1b/
Avatar of Larry Brister

ASKER

Still goes directly to next page

No delay
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That did it...
And the alert was showing me a corrupted string in the url

Thanks