[removed].href doesn't redirect

后端 未结 10 1994
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:28

    Some parenthesis are missing.

    Change

     window.location.href = "/comments.aspx?id=" + movieShareId.textContent || movieShareId.innerText + "/";
    

    to

     window.location = "/comments.aspx?id=" + (movieShareId.textContent || movieShareId.innerText) + "/";
    

    No priority is given to the || compared to the +.

    Remove also everything after the window.location assignation : this code isn't supposed to be executed as the page changes.

    Note: you don't need to set location.href. It's enough to just set location.

提交回复
热议问题