0

I have a Button setup and I am wondering how I would run the meta only once the button is pressed.

Here is the button code:

<button type="button" class="btn btn-primary" onclick="waitingDialog.show();setTimeout(function () {waitingDialog.hide();}, 900000);">
Show dialog 
</button>

and I want to run this meta once the button is pressed:

<meta http-equiv="refresh" content="3;url=http://www.example.com"/>

The onclick function basically opens a popup that tells the user that the page is loading

Thanks

-Tom

Ali Sheikhpour
  • 10,475
  • 5
  • 41
  • 82
Tom Roman
  • 13
  • 5
  • I'm not sure a meta tag is the right direction to go with this. You could check out this post for some other ideas though :) http://stackoverflow.com/questions/5294842/refresh-a-page-using-javascript-or-html Javscript is littered with ways to load a page. – user2027202827 Jun 18 '16 at 20:49
  • Thanks for the reply, but after looking at that, it just does the same thing, and re directs without the button being pushed – Tom Roman Jun 18 '16 at 20:59

2 Answers2

0

However there are several ways to redirect to a new page using javaScript and jquery, you can force the page to redirect using meta tag by adding a meta tag through jquery:

$('head').append('<meta http-equiv="refresh" content="3;url=http://www.example.com"/>');

This code should be inside your setTimeout function. As the code is too long I suggest to put it in a separate function and call it onClick.

    <button type="button" class="btn btn-primary" onclick="mydialog()">Show dialog</button>
    <scrtipt type="text-javascript">
       function mydialog(){
            waitingDialog.show();
           $('head').append('<meta http-equiv="refresh" content="3;url=http://www.example.com"/>');
            setTimeout(function () {
               waitingDialog.hide(); 
            }, 900000);
        }
    </script>
Ali Sheikhpour
  • 10,475
  • 5
  • 41
  • 82
  • So should this work? – Tom Roman Jun 18 '16 at 21:11
  • No. I have updated the answer. However I don't know what is that 900000 really? do you want to wait 900 seconds before redirecting?! – Ali Sheikhpour Jun 18 '16 at 21:21
  • No, that is to ensure that a popup stays up incase of slow internet connection – Tom Roman Jun 18 '16 at 21:26
  • Ok. So I put the **redirect meta** outside of setTimeout and it should work as you need. – Ali Sheikhpour Jun 18 '16 at 21:31
  • I am still having the problem of it automatically redirecting, without the button being pushed, and the waitingDialog box doesn't show up anymore – Tom Roman Jun 18 '16 at 21:39
0

This code help you :

<html>
<head>
    <style>
        div {
            background-color: yellow;
            color: red;
            width: 80px;
            height: 20px;
            display: none;
        }
    </style>
</head>
    <body>
        <div id="load">Loading...</div>
        <br>
        <button type="button" class="btn btn-primary">
         Show dialog 
        </button>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
        <script>
            $(document).ready(function(){
                $("button").click(function(){
                    $("#load").fadeIn(1000).delay(2000).fadeOut(1000);
                    $('head').append('<meta http-equiv="refresh" content="5;url=http://www.example.com"/>');
                })
            })
        </script>
    </body>
</html>
Ehsan
  • 12,655
  • 3
  • 25
  • 44
  • Ok, so while it is waiting, how would I make this show, this is the code: waitingDialog.show(); This is a JS thing – Tom Roman Jun 18 '16 at 22:15