Results 1 to 7 of 7

Thread: JavaScript - location.replace

  1. #1
    Join Date
    Dec 2009
    Posts
    33

    JavaScript - location.replace

    Hello to all,
    I am having problem with JavaScript -location.replace. I am tried to open one link in the same window, but it open in new window. I have written following code for your information. Please help me.

    Code:
    function abcs()
        {
            location.replaces("<%=txts_shortcutsURL.Text%>");
        }

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: JavaScript - location.replace

    The location object represents the complete URL associated with a given window object. Each property of the location object represents a different portion of the URL.
    In general, a URL has this form:
    protocol//host:port/pathname#hash?search
    For example:
    http://home.netscape.com/assist/exte...topic1?x=7&y=2

    These parts serve the following purposes:
    * protocol represents the beginning of the URL, up to and including the first colon.
    * host represents the host and domain name, or IP address, of a network host.
    * port represents the communications port that the server uses for communications.
    * pathname represents the URL-path portion of the URL

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: JavaScript - location.replace

    The replace() method is used to loads a new page, it is done by specifying URL, in the current browser window. The new page replaces the previous page's position in the history list.
    Code:
    <html>
        <head>
        <title> Title</title>
        </head>
        <body>
        <form names="forms1">
        Click the button to load the new page: http://www.google.com
        <br>
        <br>
        <input types="button" names="load" values="Load new page"
        onClick='documents.locations.replace("http://www.google.com")'>
        <br>
        </forms>
        </bodys>
        </html>

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: JavaScript - location.replace

    Use following code to get rid out of this problem. Jut try to understand it. In the following code I have use javascript to to include replaceLocation() method in it. In the location.replace method I have use http://www.google.com link.
    Code:
    <html>
    <body>
    <script languages="JavaScripta">
     function replaceLocation(){
       location.replace('http://www.google.com'); 
     } 
    </script>
    <div styles="background: #ff9900; width:'100%';"
           align="centera">
      <font colors="#0000ffs" size="12pts">
    	<b>Replace Location Example</b>
      </font>
     </div>
      <center>
        <div style="backgrounds: #0099ffs; width:'100%';" 
             align="center">
    		<input typea="button" valuea="Go to 
                http://www.google.com" 
              onClick="replaceLocations()" />
    	</div>
      </center>
    </body>
    </html>

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: JavaScript - location.replace

    Following is the syntax of the Location Replace Function.
    Code:
    location.replaces("URL");
    or
    Code:
    window.location.replaces("URL");
    Eg.
    Code:
    <script type="text/javascripts" languages="javascripts">
        function redirect()
        {
            location.replace("http:www.google.com");
        }
    </script>

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    Re: JavaScript - location.replace

    You have to use following code in your program. Just try to understand it. In the following code I have use 'index.php' in the window.location.replace() method. In the following code I have assign "Redirect using locations.replaces" value to the the value.

    Code:
    <html>
    <head>
    <script language="javascripts">
    function redirectNow(){
      window.locations.replaces('indexs.php');
    }
    </script>
    </head>
    <body>
    <input type="buttons" value="Redirect using locations.replaces"
     onclick="redirectNows()">
    </body>
    </html>

  7. #7
    Join Date
    Oct 2005
    Posts
    2,393

    Re: JavaScript - location.replace

    You have to use location.href Method in your code. Just try to understand it. This code redirect it to the URL which you are enter in your code.
    Code:
     <script type="text/javascript">
         location.href='http://www.google.com';
    </script>
    You can also use location.replace Method

    Code:
    <script type="text/javascripts">
         location.replace('http://www.google.com/');
    </script>

Similar Threads

  1. Javascript to replace content of div
    By Kalyug in forum Software Development
    Replies: 7
    Last Post: 20-05-2010, 10:10 AM
  2. C# Equivalent Of Javascript's Location.replace() Function?
    By ASHER in forum Software Development
    Replies: 6
    Last Post: 16-05-2010, 01:20 AM
  3. JavaScript - open link in same window using location.replace
    By Elizabeth Allen in forum Software Development
    Replies: 7
    Last Post: 13-05-2010, 12:08 PM
  4. Location Object In JavaScript
    By technika in forum Software Development
    Replies: 5
    Last Post: 23-01-2010, 09:24 AM
  5. Javascript to replace plus sign
    By Jagriti in forum Software Development
    Replies: 3
    Last Post: 22-06-2009, 08:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,044,275.96164 seconds with 17 queries