Reputation: 180
i want to call a php function header('Location:http://xx.yy.zz/somthing') inside a javascript function,Like given below.
<?php
<script>
function mUp(obj)
{
//here i want call the header function
}
</scipt>
//some code
?>
Pls help..
Upvotes: 0
Views: 3401
Reputation: 15492
You can't execute a PHP header function inside Javascript.
Javascript runs inside the browser, While PHP runs on your server.
do something like
window.location.href = "http://xx.yy.zz/somthing";
Upvotes: 0
Reputation: 178
I guess you want to do a redirect, it would be good to redirect through javascript itself , if you want to write PHP code inside, just use PHP tags in between and write the code..or echo the javascript code and write PHP code.
Upvotes: 0
Reputation: 5207
By now you probably have noticed that If you put a php header redirect in after already sending html/any text to the client's browser, you get an error; this is because the header() function tells the server to cancel the output from the current page and redirect to another page at the server-side. so either you should find a way to execute that header function before printing any html/js to the broswer, or you could do a javascript redirect:
<script type="text/JavaScript">
window.location.href="http://xx.yy.zz/somthing";
</script>
please comment if this isn't clear enough
Upvotes: 0
Reputation: 2526
There is no need to put php code. .Just try this...
<script>
function mUp(obj)
{
window.location="http://xx.yy.zz/somthing";
}
</scipt>
Upvotes: 0
Reputation: 8272
why PHP function for redirecting ? If you want to redirect simply
document.location.href='http://xx.yy.zz/somthing';
Upvotes: 0
Reputation: 11890
Why don't you use directly the javascript version?
Have a look to window.location object.
Upvotes: 0
Reputation: 167162
The code similar to PHP's header()
location
function:
header('Location:http://xx.yy.zz/somthing');
In javascript is,
location.href = "http://xx.yy.zz/somthing";
Both does the same redirect for the users, but the former one returns a HTTP Status of 301.
Upvotes: 0
Reputation: 6660
This is something for JavaScript, not for PHP:
<script>
function mUp(obj)
{
document.location.href = 'http://www.example.com/';
}
</script>
Upvotes: 0
Reputation: 72975
Thats not how it works.
Use:
window.location = "http://xx.yy.zz/somthing";
Upvotes: 1