Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. window.location.replace

window.location.replace

Scheduled Pinned Locked Moved ASP.NET
javascriptsysadminsecurityhelpquestion
13 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Satish_S

    hi i have following line of code randomNumber = Math.round(100000*Math.random()); url = "sample.aspx?host="+host+"&port="+port+"&targetName="+targetName+"&imageMode="+imageMode+"&randomNumber="+randomNumber; alert("callbegins:Authentication.aspx"); location.replace(url); alert("callends:Authentication.aspx"); break; in the Authentication.aspx page i have the client code which connects a device. when the line of the above code getting executed it is redirecting to the URL server side but my javascript code are not working. when i call alert after replace then the page getting redirected and client code is getting excuted. i am confused that why when putting alert after replace it is redirecting and calling client code but when the alert commented then the client code not working. this issue is in fire fox, and in IE9 its not at all redirecting if alert also there. please clarify me why this happens thanks

    J Offline
    J Offline
    jkirkerx
    wrote on last edited by
    #2

    I didn't take the time to look it up, but wouldn't it be window.location(url); to use javascript to redirect to another page? If it's the same page, I don't see the purpose of it. The alert is just a message box, used for diagnosing values, or to tell the client something important. FYI; You need to encode the url with utf-8 or something before calling window.location(url)

    S 1 Reply Last reply
    0
    • J jkirkerx

      I didn't take the time to look it up, but wouldn't it be window.location(url); to use javascript to redirect to another page? If it's the same page, I don't see the purpose of it. The alert is just a message box, used for diagnosing values, or to tell the client something important. FYI; You need to encode the url with utf-8 or something before calling window.location(url)

      S Offline
      S Offline
      Satish_S
      wrote on last edited by
      #3

      thanks for your time & reply... Encoding also didn't helped me. the page getting opened when i am using window.open("URL"); but not when using window.location.replace("URL");

      J 1 Reply Last reply
      0
      • S Satish_S

        thanks for your time & reply... Encoding also didn't helped me. the page getting opened when i am using window.open("URL"); but not when using window.location.replace("URL");

        J Offline
        J Offline
        jkirkerx
        wrote on last edited by
        #4

        take the double quotes off url. I think you misinterpreted encoding. You just want to make sure that the url you create is in the correct format. encodeURI and encodeURIComponent. But skip that for now. window.location(url) will redirect the current page to a new page indicated by url window.open(url) will open a new browser window, or a new tab, with the value url it always works unless your url value has an error in it. I would have to see the string you created to see if it is a valid format.

        S 1 Reply Last reply
        0
        • J jkirkerx

          take the double quotes off url. I think you misinterpreted encoding. You just want to make sure that the url you create is in the correct format. encodeURI and encodeURIComponent. But skip that for now. window.location(url) will redirect the current page to a new page indicated by url window.open(url) will open a new browser window, or a new tab, with the value url it always works unless your url value has an error in it. I would have to see the string you created to see if it is a valid format.

          S Offline
          S Offline
          Satish_S
          wrote on last edited by
          #5

          url = "Authentication.aspx?host=" + host + "&port=" + port + "&targetName=" + targetName + "&imageMode=" + imageMode + "&randomNumber=" + randomNumber; As you suggested i used as below,but that too didnt helped me out. url=encodeURIComponent(url); window.location.replace(url); (Authentication.aspx%3Fhost%3D172.2.542.166%26port%3D5900%26targetName%3D172.2.542.166%26imageMode%3DColor%26randomNumber%3D79148) this is the url i need to redirect to, i am getting break point in c# but my client side not getting executed.even i placed an alert in body onload,alert is not shown.this is happening in IE9,FF,chrome all this are HTML5 new browsers. thanks for the reply..

          J 1 Reply Last reply
          0
          • S Satish_S

            url = "Authentication.aspx?host=" + host + "&port=" + port + "&targetName=" + targetName + "&imageMode=" + imageMode + "&randomNumber=" + randomNumber; As you suggested i used as below,but that too didnt helped me out. url=encodeURIComponent(url); window.location.replace(url); (Authentication.aspx%3Fhost%3D172.2.542.166%26port%3D5900%26targetName%3D172.2.542.166%26imageMode%3DColor%26randomNumber%3D79148) this is the url i need to redirect to, i am getting break point in c# but my client side not getting executed.even i placed an alert in body onload,alert is not shown.this is happening in IE9,FF,chrome all this are HTML5 new browsers. thanks for the reply..

            J Offline
            J Offline
            jkirkerx
            wrote on last edited by
            #6

            I need to see the url string after construction, just use alert(url);, and copy the result in this window. Most likely, you string may be corrupt, and the function failed.

            J S 2 Replies Last reply
            0
            • J jkirkerx

              I need to see the url string after construction, just use alert(url);, and copy the result in this window. Most likely, you string may be corrupt, and the function failed.

              J Offline
              J Offline
              jkirkerx
              wrote on last edited by
              #7

              If you can't get construct the url, show me your header code for pointing to the js file, and post the entire javascript function. I'm taking off in 20 minutes to watch big bang theory on tv, so hurry.

              S 1 Reply Last reply
              0
              • J jkirkerx

                I need to see the url string after construction, just use alert(url);, and copy the result in this window. Most likely, you string may be corrupt, and the function failed.

                S Offline
                S Offline
                Satish_S
                wrote on last edited by
                #8

                Authentication.aspx?host=172.2.542.166&port=5900&targetName=172.2.542.166&imageMode=Color&randomNumber=15563 this is the one i am getting thru alert. thanks

                1 Reply Last reply
                0
                • J jkirkerx

                  If you can't get construct the url, show me your header code for pointing to the js file, and post the entire javascript function. I'm taking off in 20 minutes to watch big bang theory on tv, so hurry.

                  S Offline
                  S Offline
                  Satish_S
                  wrote on last edited by
                  #9

                  if(xmlhttp.status == 200) { switch (xmlhttp.responseText) { //If the browser connected to remote MFP (For Anonymous connections). case "authenticationrequired": //Generate random number and attach it to the endpoint to avoid caching problems. randomNumber = Math.round(100000*Math.random()); url = "Authentication.aspx?host=" + host + "&port=" + port + "&targetName=" + targetName + "&imageMode=" + imageMode + "&randomNumber=" + randomNumber; // url=encodeURIComponent(url); alert(url); // // window.open(url); window.location(url); default: case... } }

                  J 1 Reply Last reply
                  0
                  • S Satish_S

                    if(xmlhttp.status == 200) { switch (xmlhttp.responseText) { //If the browser connected to remote MFP (For Anonymous connections). case "authenticationrequired": //Generate random number and attach it to the endpoint to avoid caching problems. randomNumber = Math.round(100000*Math.random()); url = "Authentication.aspx?host=" + host + "&port=" + port + "&targetName=" + targetName + "&imageMode=" + imageMode + "&randomNumber=" + randomNumber; // url=encodeURIComponent(url); alert(url); // // window.open(url); window.location(url); default: case... } }

                    J Offline
                    J Offline
                    jkirkerx
                    wrote on last edited by
                    #10

                    It looks good. I'd have to say in theory, that the . in the ip address are interfering, there being picked up as a special url character, so you have to encode the dots. Even if you encode the dots, there still dots. I saw the remarked out urlencode, looks like you tried it, but it still didn't work. I'm watching my bowling videos now, but check the valid url character set, try the encoding again, paste the results directly into the url bar, until you find something that works. You may have to replace the dots with another char, to get it to work. try I think %20 which is a space, or an underscore _, I can't remember the encoded value for it, but there are charts on the web, url encoding %20 should find a chart. Be back tommorow, I'm -8 GMT. I have bowling tommorrow night, so it has to be before 18:00 -8 gmt. Edit: I thinking that the url is a bad idea. Maybe a hidden textbox to store the ip is better.

                    S 1 Reply Last reply
                    0
                    • J jkirkerx

                      It looks good. I'd have to say in theory, that the . in the ip address are interfering, there being picked up as a special url character, so you have to encode the dots. Even if you encode the dots, there still dots. I saw the remarked out urlencode, looks like you tried it, but it still didn't work. I'm watching my bowling videos now, but check the valid url character set, try the encoding again, paste the results directly into the url bar, until you find something that works. You may have to replace the dots with another char, to get it to work. try I think %20 which is a space, or an underscore _, I can't remember the encoded value for it, but there are charts on the web, url encoding %20 should find a chart. Be back tommorow, I'm -8 GMT. I have bowling tommorrow night, so it has to be before 18:00 -8 gmt. Edit: I thinking that the url is a bad idea. Maybe a hidden textbox to store the ip is better.

                      S Offline
                      S Offline
                      Satish_S
                      wrote on last edited by
                      #11

                      Really thanks for your time & reply.... Your answers are really helped me out very well to debug depth about URL encoding cooncepts. In the mean time i have gone through some articles about this issue and tried by returning false after a function call. And also where i am using location.replace(url). now it is working fine but yet to test in all scenarios and all browser versions. i will get back to you on the said time tommorrow. bye take care.

                      J 1 Reply Last reply
                      0
                      • S Satish_S

                        Really thanks for your time & reply.... Your answers are really helped me out very well to debug depth about URL encoding cooncepts. In the mean time i have gone through some articles about this issue and tried by returning false after a function call. And also where i am using location.replace(url). now it is working fine but yet to test in all scenarios and all browser versions. i will get back to you on the said time tommorrow. bye take care.

                        J Offline
                        J Offline
                        jkirkerx
                        wrote on last edited by
                        #12

                        Oh, That was fast. Browsers pretty much work the same, so since it failed on all browsers means that the problem was not with the browser. You have to encode everything you transmit, UTF8 is a set of chars from 1 to 127, that is unicode, and decode everything you receive. asp.net is a high level wrapper, that talks to c++ code underneath, so the principles of character encoding still apply. They don't tell you that in the books. Have fun and go forward, your day will be productive. jkirkerx Oh, give me a vote, some day I might be a mvp.

                        S 1 Reply Last reply
                        0
                        • J jkirkerx

                          Oh, That was fast. Browsers pretty much work the same, so since it failed on all browsers means that the problem was not with the browser. You have to encode everything you transmit, UTF8 is a set of chars from 1 to 127, that is unicode, and decode everything you receive. asp.net is a high level wrapper, that talks to c++ code underneath, so the principles of character encoding still apply. They don't tell you that in the books. Have fun and go forward, your day will be productive. jkirkerx Oh, give me a vote, some day I might be a mvp.

                          S Offline
                          S Offline
                          Satish_S
                          wrote on last edited by
                          #13

                          Really thanks for your time & reply.... Your answers are really helped me out very well to debug depth about URL encoding cooncepts. In the mean time i have gone through some articles about this issue and tried by returning false after a function call. And also where i am using location.replace(url). now it is working fine but yet to test in all scenarios and all browser versions. i will get back to you on the said time tommorrow. bye take care.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups