Considering @Guilherme Nascimento’s comments:
works intermittently or that oscillates is not working, at the moment that redirect page, even if some script is running something will be destroyed may or may not fail, that there is no sense and nor should be done, things have to be planned to work and not by "maybe it works" or "think it works". Simply href="icone.html" will redirect and at this point any attempt to execute script on a page that is downloading to load another will be a factor of "competition" no guarantees.
I suggest you remove href and put window.Location in the pick functionInfo()
Why use or a onclick
or another href
?
Imagine a scenario of competition
function pegarInfo(){
setTimeout(function(){
alert("isso deve executar dentro de 2 segundos");
}, 2000);
}
<a href="icone.html" onclick="pegarInfo()">Teste</a>
function pegarInfo(){
setTimeout(function(){
alert("isso deve executar dentro de 2 segundos");
window.location = "icone.html";
}, 2000);
}
<a onclick="pegarInfo()">Teste</a>
Caro Igor, pegInfo won’t work because href probably directs before javascript runs (cc @Marceloboni)
– Guilherme Nascimento
@sam is a function that only stores the information with a sessionStorage.
– Igor Costa
Ever tried to put folder directory? How
..\icone.html
– Marcos Paulo S. Rezende
@Sam, considering the remaining 1%, would put a
window.location
in functionpegarInfo()
– user60252
Beauty, if he puts an Alert in the function will see that the onclick works before the href
– user60252
@sam works intermittently or that oscillates is not working, the moment that redirect page, even if some script is running something will be destroyed may or may not fail, that there is no sense and nor should be done, things have to be planned to work and not by "maybe it works" or "think it works". Simply href="icone.html" will redirect and at this point any attempt to execute script on a page that is downloading to load another will be a factor of "competition" no guarantees.
– Guilherme Nascimento
@sam doing right is quite different from what this done there, so I’ve already commented will not work, because simply have to redo. It’s a matter of seconds, there’s no right way about it, and there’s no reliance on a browser.
– Guilherme Nascimento
@Igor would probably be better to explain what you want to do. Normally either you use href, or the onclick. There will hardly be any real reason to use both (maybe you have the impression of being necessary in your case, but it’s probably lack of knowing a real solution - probably to put the redirect on the JS).
– Bacco
@Leocaracciolo com window.location.assign("imovel.html") works perfectly, thank you very much.
– Igor Costa
@Bacco well I’m wanting that when the person clicks on the link the browser save the information and redirect the person to another page, and on the page that was redirected I can fetch the information from the browser and complete the gaps like "Name" etc.
– Igor Costa
@sam is what Bacco said and what I said, is the timing, the same as what I said: "It’s a matter of seconds" or less than seconds. This is called "competition" in the running time of two tasks.
– Guilherme Nascimento
Igor Costa is the most sensible way to apply (window.Location within the function) . See how your question yielded a long discussion rs
– user60252
@Igorcosta in this case really seems to me that Leo’s solution is appropriate, take the href and leave the link in Location. So it’s guaranteed to run the code you want, and Location will play its role only later. And yet you have to see if the code executed is synchronous. If it is asynchronous, it can still give a timing problem (Location kills your JS before it is finished).
– Bacco
I happen to remember a post on facebook of a certain moderator of the network that I shared.... your comment "raising the possibility of functioning normally", Wrong is still wrong even if everyone does it wrong, and right is still right even if nobody does it right.
– MarceloBoni