Welcome Guest, Not a member yet? Register   Sign In
javascript before redirect
#1

[eluser]syntaxerror[/eluser]
hi,
can anyone please tell me how to execute javascript first before redirect?

i have a script here but it skips javascript and executes javascript.
Code:
[removed]
            alert ("Put your warning text here!")
            [removed]
        <?php
            redirect('Front_cont/input_dir_ufpb_wp');
        ?>

i want to check if a file exist,
if that file doesnt exist, it pops up an alert box and return to the
input text page.

the problem is it skips the alert message and just redirect the page.

please advice.

thanks
#2

[eluser]Nick Husher[/eluser]
I don't know for sure, but I think that CI uses a header redirect rather than an HTML redirect when you use the redirect function. You should think about doing the redirection in javascript-

Code:
<html>
<head>
  <title>File does not exist!</title>
</head>
<body>
  <h1>ONOES!<h1>
  <p>
   The file you requested does not exist!
   Sit tight and your browser will redirect you in a second. Or,
   <a href="&lt;?=base_url().'/Front_cont/input_dir_ufpb_wp' ?&gt;">
    click here to continue
   </a>.
  </p>
  <>script type="text/javascript">
   var redirect = function() {
    document.location = &lt;?=base_url().'/Front_cont/input_dir_ufpb_wp' ?&gt;
   }

   setTimeout(redirect, 5000); // call redirect in 5 seconds
  <>/script>
&lt;/body&gt;
&lt;/html&gt;
#3

[eluser]syntaxerror[/eluser]
thanks!
but the javascript isnt working.
it didnt redirect in 5 seconds.
#4

[eluser]syntaxerror[/eluser]
i made it working.
i made a new page,
redirect to that page if a file doesnt exist.
and in that page i have a javascript.
Code:
&lt;html&gt;
&lt;head&gt;
[removed]
&lt;!--
function delayer(){
    [removed] = "&lt;?php echo 'input_dir_ufpb_wp'; ?&gt;"
}
//--&gt;
[removed]
&lt;/head&gt;
&lt;body&gt;
<h2>Prepare to be redirected!</h2>
<p>This page is a time delay redirect, please update your bookmarks to our new
location!</p>

&lt;/body&gt;
&lt;/html&gt;
#5

[eluser]Nick Husher[/eluser]
Yeah, I mistyped. Replace document.location with [removed], and it should work.

Note that the redirect requries javascript to be enabled to work, which is less than ideal. That's why I added the hard HTML link.

Also, you can avoid javascript alltogether if you use a meta-tag redirect: http://webmaster.indiana.edu/tool_guide_...atag.shtml




Theme © iAndrew 2016 - Forum software by © MyBB