locked
JS Help RRS feed

  • Question

  • User1324715958 posted

    I'm trying to build a simple script to redirect a user if their url contains a certain string value.  I dont have any errors but its not redirecting. Here is the code:

    Code:
    var URL = window.location.href ;
           if(URL.indexOf("ParentDataObject=InvoiceDetail") > -1)
           {
                  URL = URL.replace("InvoiceDetail", "Invoice%20Detail");
                  window.location = URL;
           }
    

    Friday, May 10, 2019 6:08 PM

All replies

  • User465171450 posted

    try window.location.href = URL;

    Friday, May 10, 2019 6:52 PM
  • User288213138 posted

    Hi  UOKSoftware,
     
    I tried to reproduce your problem and found that your code is working properly.
     
    The code:

    <script type="text/javascript">
            $(document).ready(function () {
                var URL = "WebForm1.aspx?q=Draw";
                if (URL.indexOf("w") > -1) {
                    URL = URL.replace("Draw", "Dr%20aw");
                  
                    window.location = URL;
                }
            });
        </script>
    
    protected void Page_Load(object sender, EventArgs e)
            {
                Response.Write(Request["q"]);
            }
    

    The Result:

    Best Regards,

    Sam

    Monday, May 13, 2019 8:16 AM