[removed]() not working, not opening page

后端 未结 5 1343
误落风尘
误落风尘 2020-12-14 16:54

I have a submit button with a onClick:

&
相关标签:
5条回答
  • 2020-12-14 16:57

    Setting the location works just fine, but then the form is submitted, which will reload the current page instead.

    Return false from the method:

    function sendmail() {   
      window.location.href = "http://www.rainbowcode.net/index.php/profiles/mail?="+mailid;
      return false;
    }
    

    and return that status in the event to stop the submit:

    <input type="submit" value="Send" onclick="return sendmail()">
    
    0 讨论(0)
  • 2020-12-14 17:07

    I spent 2 days trying every solution shown here and elsewhere, to no avail. Then I removed the form tags, which served no purpose since there was no submit button, and the problem went away using:

    window.location = 'mypage.php', true;
    
    0 讨论(0)
  • 2020-12-14 17:16

    Try using replace function instead

    window.location.replace('http://www.rainbowcode.net/index.php/profiles/mail?='+mailid)
    
    0 讨论(0)
  • 2020-12-14 17:18

    If you need to open a new window, you should use the window.open() method. window.location refers to the current windows address, and will only - when using window.location.reload() - reload the CURRENT window.

    0 讨论(0)
  • 2020-12-14 17:22

    Solid answers already but why fight the system? Particularly if you've called with jquery or onClick - there might not be an inline return is my point - so instead you could just change the action on the submit:

    document.form.action = 'http://www.rainbowcode.net/index.php'

    then you can pick any of the form variables if you need them or ignore if not.

    0 讨论(0)
提交回复
热议问题