Jump to content

why alert() not execute if I use before header()??


iskhan

Recommended Posts

function goto_page()
{
        if(.............)
          {
           <? alert("Error:............"); <?php
           header("abc.php");
           }
}

 

Javascript is executed at client side i.e in browser. 

 

But in above case you are redirecting the page to another location through PHP before sending o/p to the browser,

If browser is not getting any data it won't interpret it.

 

so u can use javascript to redirect the page 

 

alert('Error:---')
like location.href = 'abc.php';

Try this...

 


<?php
function goto_page()
{
        if(true){
		?>
		<script language="JavaScript1.2" type="text/javascript">
			alert("Error");
		</script>
		<?php
           header("http://www.google.com");
           }
}

goto_page();
?>

yaa if true.. because i dont know which condition he is using.. i always want my condition to be true.. its just an example.... he can replace it by his own condition.....

 

The only problem he is facing that he want to display an alert box.......and then he want user to be redirected to specific page....

 

So, my code solves the prob...4 him....

as your requirement is only to redirect user. use javascript redirection.. use below code .

 

<?php
function goto_page()
{
        if(true){
		?>
		<script language="JavaScript1.2" type="text/javascript">
			alert("Error");
			window.location = "http://www.google.com";
		</script>
		<?php
        
           }
}

goto_page();
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.