0

Here is my HTML button:

<button class="button-brightgreen" onclick="cancelbutton();">Cancel</button>

Here is my JavaScript redirect:

function cancelbutton() {
    var cancelURL = 'http://localhost:51937/php/searchUsers.php';
    $(location).attr('href', cancelURL);
}

This is on my editUser.php page. This code works fine for me, except when there is a php GET string in the current URL such as ?user_id=19

When there is a GET in the URL and I click the cancel button, it takes me back to the same page (editUser.php) and displays ""

How can I get the redirect to work when there is a GET in the current URL?

1
  • try like javascript: window.history = "http://localhost:51937/php/searchUsers.php"; Commented May 28, 2015 at 13:19

2 Answers 2

1

You can check if the string user_id is present in the current URL, if present then redirect.

if (window.location.href.indexOf('user_id=') > -1) {
    window.location.href = 'newURL';
}
Sign up to request clarification or add additional context in comments.

Comments

0

I figured my problem out. The button was inside a form and when clicked, it would submit the form and the "" was coming from my PHP page. Taking the button out of the form, fixed my problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.