Javascript redirect not working anyway

There are a lot of questions. I tried all the solutions - nothing helps.

I want to open a new page in one tab using 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 are my functions. js:

function testUrl()
{

window.location = "content.html";

}

function loginClient()
...//more functions

I tried other ways:

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 on Windows) and Chrome (Debian). BUT works if I installed:

window.open("content.html")

but in a new tab, this is not a solution, I need it on the same tab.

BUT, if I try to debug it using Firebug and always click "Step in" than all solutions. And if I set up alert () before the redirect, it works too.

The console does not show errors. I have no idea, help.

RESOLVED: Thanks @lonesomeday!

this solution:

$(document).ready(function(){
    $("#loginClient").click(function(event){
      event.preventDefault();
      window.location = "content.html";
    });
});
+4
1

onclick <input type="image">. submit. , , . , HTTP-, window.location.

, .

- false . - :

onclick="return testUrl()" 

JS:

function testUrl()
{
window.location = "content.html";    
return false;
}

, Javascript event.preventDefault.

+5

All Articles