There are many same questions here. I tried all solutions - nothing helps.
I want to open new page in some tab with javascript. Here is my HTML:
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" ></script>
<script src="functions.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="css.css" rel="stylesheet" type="text/css" />
</head>
<body>
...
<label>
<input type="image" name="imageField" id="loginClient" onclick="testUrl()" src="images/index_33.gif" />
</label>
...
</body>
</html>
Here is my functions.js:
function testUrl()
{
window.location = "content.html";
}
function loginClient()
...//more functions
I tried other ways too:
window.location.replace("content.html")
top.location="content.html"
window.location.assign("content.html")
window.open("content.html", "_self")
window.location.href="content.html"
window.event.returnValue = false;
window.location = "content.html";
setTimeout(function(){window.location.assign("content.html");return false;},500)
nothing works, I tried it in Opera, Firefox (all in Windows) and Chrome (Debian).
BUT it works if I set:
window.open("content.html")
but in new tab, isn't solution, I need it in same tab.
BUT if I try to debug it with Firebug and click always "Step into" than all solution work. And if I set alert() before redirecting, it works too.
Console shows no errors.
I have no idea, help.
RESOLVED: Thanks to @lonesomeday!
this is the solution:
$(document).ready(function(){
$("#loginClient").click(function(event){
event.preventDefault();
window.location = "content.html";
});
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…