[removed].href doesn't redirect

后端 未结 10 1974
Happy的楠姐
Happy的楠姐 2020-12-18 17:40

I know this is a question much discussed but I can\'t figure out why it does not work for me.

This is my function:

function ShowComments(){

 alert(\         


        
10条回答
  •  粉色の甜心
    2020-12-18 18:29

    In case anyone was a tired and silly as I was the other night whereupon I came across many threads espousing the different methods to get a javascript redirect, all of which were failing...

    You can't use window.location.replace or document.location.href or any of your favourite vanilla javascript methods to redirect a page to itself.

    So if you're dynamically adding in the redirect path from the back end, or pulling it from a data tag, make sure you do check at some stage for redirects to the current page. It could be as simple as:

    if(window.location.href == linkout)
    {
        location.reload();
    }
    else
    {
        window.location.href = linkout;
    }
    

提交回复
热议问题