简体   繁体   中英

redirecting to next page

I wrote a javascript function to go to a particular page if it came from a particular page.

Function:

function proceed()
{

  if( document.referer == "http://abcd.com/index.php?action=SignUp")
  {
    return document.location.href = "http://abcd.com/editprofile.php?action=editprofile";
  }
}

Submit button for a form in current page(b):

What i want is to go through a sequence of pages a->b->c , where a is previous , b is current , and c is next in my case. b has a form, on submitting values to the form, it should also call the javascript function and then go to the page c.

Can anybody help me find out where is the mistake? Any help would be highly appreciated. Thanks.

To be more accurate you will have to provide more of your application's code.

Solution seems to be the following. Use the submit attribute for your button:

<button type="button" onclick="proceed(); alert('You are not authorized to execute this action!');">Click Me!</button

Since you have a form I guess there's also some php/cgi script that will handle the form's data!?
In that case your form won't continue to that script if you override your submit button via javascript in such way that it loads another page (other cases like validation do work that way, of course).

So

  1. Your submit button has spaces next to the onclick attribute: onclick = "javascript... should be onclick="javascript... .
  2. Your function proceed() should return true for the submit to perform.
  3. Even after all syntax correction, there's still something odd. After all, you can only give one "next page" functionality to your submit button. So what should the form call:

    • your php or cgi script? Then you can build a redirect to page "c" into that one.
    • your page "c"? Then what do you need the form for?
    • both, but independently? In that case I suggest a javascript popup from proceed() displaying page "c" and returning true so the form continues with its script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM