Jquery does not point to another page [closed]

1

I have a website with some buttons. When you click the buttons, they are directed to the respective pages, but there is a button that does not address, it only remains on the same page. The code I'm using for it is:

    $('#btnSeguroViagem').on("click",function()
          {
              var novaURL = "seguro-viagem.php";
              $(window.document.location).attr('href',novaURL);
          });
<button type="submit" name="Submit" id="btnSeguroViagem" value="Solicitar"  class="btn btn-danger btn-small"><i class="fa fa-plus-square"></i> Solicitar Seguro Viagem</button>

Can anyone tell me why this guy is not going? The page exists, I removed all the content and I put a sentence, but nothing. Clicking the button gives the post but stays on the same page and does not point to the secure-travelpage.php. The strange thing is that I already gave an alert () inside the call and arrives correctly.

    
asked by anonymous 18.10.2015 / 23:54

2 answers

2

In this case jQuery is not accurate. The solution goes through simple javascript. Here are two options:

Option 1:

window.location.href = "http://pt.stackoverflow.com";
// ou uma variante com o mesmo efeito
window.location.assign("http://pt.stackoverflow.com");

Option 2:

window.location.replace("http://pt.stackoverflow.com");

The difference between these two methods is that the first one makes it possible to click back in the history of the browser and go to the previous page. The second one replaces the current page and when clicking to go back in the story, the home page is not accessible (has been replaced in history).

If you want the user to open a new window (without losing the source window), you can use:

window.open("http://pt.stackoverflow.com");

This window.open () method also allows you to pass parameters / options such as size, content, etc.

Source: How to redirect the user to another page in JavaScript / jQuery?

    
19.10.2015 / 00:00
0

Although you have already found your answer, I believe there are several simpler ways to get the expected result.

A

Since you are already using Bootstrap , you can find information available on the framework :

  

Use the button classes on an < a > , < button & gt ;, or < input > element.

This means that you can create a a tag as the same view as a button . Example:

<a class="btn btn-danger btn-small" href="seguro-viagem.php">
    <i class="fa fa-plus-square"></i>Solicitar Seguro Viagem
</a>

Using the a tag, you still have the benefit of being able to use the target attribute.

FORM

With the form tag you can call the desired URL using the action attribute. Example:

<form action="seguro-viagem.php">
    <button type="submit" value="Solicitar" class="btn btn-danger btn-small">
        <i class="fa fa-plus-square"></i> Solicitar Seguro Viagem
    </button>
</form>

Javascript

Through javascript you can access an object from the window called location . This object has a property called href , whose value is the address of the current window. By changing this property, you redirect the client to a new address. Example:

location.href = 'seguro-viagem.php';
    
19.10.2015 / 04:12