javascript redirect not working anyway

前端 未结 1 1453
孤街浪徒
孤街浪徒 2020-12-19 08:15

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:

<         


        
相关标签:
1条回答
  • 2020-12-19 09:02

    You've got this onclick attribute on an <input type="image"> element. Image inputs are effectively submit buttons. When you click it, it is activated, and the form is submitted. When a form is submitted, it cancels any ongoing HTTP requests, such as your window.location call.

    So you need to prevent the form submission from going ahead.

    The quick and dirty way to do this is to return false from your event handler. Something like this:

    onclick="return testUrl()" 
    

    With the JS:

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

    The prettier way to do this would be to bind your event handlers with Javascript and use event.preventDefault.

    0 讨论(0)
提交回复
热议问题