简体   繁体   中英

document.location.href for relative path

I want to relocate on button click to a relative url :

<button onclick="document.location.href='/Recruiters.aspx'"></button>

but this is not working...

Any suggestions?

The default type of a button is "submit" so when inside a form, clicking the button submits it. Though it should first redirect but it's worth a shot:

<button type="button" onclick="document.location.href='/Recruiters.aspx'"></button>

Your onclick needs to be a handler. You could do it like this:

<script>
    function redirect()
    {
        window.location.href='/Recruiters.aspx';
    }
</script>

<button onclick="redirect()"></button>

If you don't want to use a handler you can still do it inline like this:

<button onclick="javascript: window.location.href='/Recruiters.aspx';"></button>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM