0

How do I open a php page from javascript function ?

  1. window.location = "http://www.google.com";
  2. window.location.href = "http://www.google.com";
  3. location.href = "http://www.google.com";

None of them is working.
Even put in php.ini

allow_url_fopen = on

What is wrong at my approach?

Alan Wells
  • 30,746
  • 15
  • 104
  • 152
user1702736
  • 51
  • 1
  • 6

4 Answers4

1

If you have this javascript embedded within <script> tags it should work:

<script type="text/javascript">
  window.location = "http://www.google.com";
</script>

However, you cannot cause a PHP script to be included within a page you are writing with thsi javascript function: It will only redirect the browser to google or whatever other page you have set in window.location. You can include a PHP script from within a PHP page using the PHP include() or require() functions:

<?php
  include('file.php');
?>
L0j1k
  • 12,255
  • 7
  • 53
  • 65
  • ist a function in the header ... tags are there for all functions – user1702736 Sep 27 '12 at 09:33
  • window.location = "../../member/en/member.php"; – user1702736 Sep 27 '12 at 09:36
  • As long as the page is accessible normally (for example just writing the address into the address bar and it is working there), then your `window.location = "../../member/en/member.php";` *should* work. I would check to make sure that the location is accessible normally. – L0j1k Sep 27 '12 at 09:38
  • full code :function callmemberpage() { alert("callmemberpage was called"); window.location = '../../member/en/member1.html'; } – user1702736 Sep 27 '12 at 10:24
  • Ignore what I said about headers. That is for the PHP header() function. :P Is it still not working? – L0j1k Sep 27 '12 at 10:26
1
window.location = "http://www.google.com";

Should work..

I think your javascript code contain some error so it is not working.

Vijay Verma
  • 3,660
  • 2
  • 19
  • 27
0

So php.ini's line allow_url_fopen has nothing to do with this. It is to allow or not a url to be given to the fopen function of PHP.

Here what you want to do is to redirect a user to another page using window.location = '/page.php'.

Unless by open you meant getting loading inside the actual page, in this case have a look at the mdn documentation about XHR. And you should be using jQuery's load function.

3on
  • 6,291
  • 3
  • 26
  • 22
-1
window.location.href = "http://www.google.com";

That will only redirect the user to Google.

But you can't load a page in a JS variable, every browser have a "cross-domain" restriction (unless the page is on the same domain as you JS file & your visitor).

Thibault Henry
  • 816
  • 6
  • 16
  • 1
    CORS issue only occur with XHR. – 3on Sep 27 '12 at 09:26
  • after the users login and his status is known i want to foreward the user to different new pages .... used google to avoid that my site is not working or not found – user1702736 Sep 27 '12 at 09:28
  • window.location = "../../member/en/member.php"; that is what i need or window.location = "../../admin/en/admin.php"; – user1702736 Sep 27 '12 at 09:38