Results 1 to 8 of 8

Thread: JavaScript - open link in same window using location.replace

  1. #1
    Join Date
    Mar 2010
    Posts
    197

    JavaScript - open link in same window using location.replace

    Hello,
    I am trying a java script that will open a link in the same window. I have tried a number of code modifications and alternatives for this but non of them work
    Here is my code
    Code:
        function test()
        {
            location.replace("<%=urltest.Text%>");
        }
    Any help regarding this is appreciated. Thank you for your help.

  2. #2
    Join Date
    Nov 2009
    Posts
    446

    Re: JavaScript - open link in same window using location.replace

    Hello,
    See the code below
    Code:
      function rplclctn(){
       location.replace('you address here'); 
     }
    And then to implement
    Code:
    <html>
    <body>
    <script language="JavaScript">
     function rplclctn(){
       location.replace('you address here'); 
     } 
    </script>
    <div style="background: #ff9900; width:'100%';"
           align="center">
      <font color="#0000ff" size="12pt">
    	<b>Replace Location Example</b>
      </font>
     </div>
      <center>
        <div style="background: #0099ff; width:'100%';" 
             align="center">
    		<input type="button" value="Go to 
                you address here" 
              onClick="rplclctn()" />
    	</div>
      </center>
    </body>
    </html>

  3. #3
    Join Date
    Nov 2009
    Posts
    583

    Re: JavaScript - open link in same window using location.replace

    Hello,
    You can use both of them
    location.href Method
    Code:
    <script type="text/javascript">
         location.href='you address here';
    </script>
    location.replace Method
    Code:
    <script type="text/javascript">
         location.replace('you address here/');
    </script>
    I hope this will help you.

  4. #4
    Join Date
    Nov 2009
    Posts
    330

    Re: JavaScript - open link in same window using location.replace

    Hello,
    See if this code can help

    Code:
    <html>
    <head>
    <script language="javascript">
    function rednw(){
      window.location.replace('index.php');
    }
    </script>
    </head>
    <body>
    <input type="button" value="Redirect using location.replace"
     onclick="rednw()">
    </body>
    </html>

  5. #5
    Join Date
    Nov 2009
    Posts
    335

    Re: JavaScript - open link in same window using location.replace

    Hello,
    You can use
    Code:
    location.replace("URL");
    Or
    Code:
    window.location.replace("URL");
    and then your program
    Code:
    <script type="text/javascript" language="javascript">
        function redirect()
        {
            location.replace("address here");
        }
    </script>

  6. #6
    Join Date
    Nov 2009
    Posts
    518

    Re: JavaScript - open link in same window using location.replace

    Hello,
    Check out the following code
    Code:
        <script type="text/javascript">
          var pswd = prompt("your data here", "");
          if (pswd == "Lernen") {
            location.replace("http://address here");
          } else {
            location.replace("");
          }
        </script>

  7. #7
    Join Date
    Nov 2009
    Posts
    343

    Re: JavaScript - open link in same window using location.replace

    Hello,
    See if this helps
    Code:
    <tr>								
        <td width="23%">
      	 <?php echo $some text; ?>
        </td>
        <td>
            <?php echo $add info; ?>? 
    	<?php 
    												
    	if ($_REQUEST["notice here"] == "2") {
    
    	?>									
    	<input type="checkbox" name="notice here" value="2" onClick="javascript:window.location.replace('example.php','title=title')" <?php if ($_REQUEST["notice here"] == "2") {echo "checked";} ?>> <-  (Problem hier!)
    	<?php
    									
    	} else {
    									
    	?>
    	<input type="checkbox" name="notice here" value="2" onchange="check(this)" <?php if ($_REQUEST["notice here"] == "2") {echo "checked";} ?>>
    	<?php
    									
    	}
    									
    	?>
       </td>								
    </tr>

  8. #8
    Join Date
    Nov 2009
    Posts
    343

    Re: JavaScript - open link in same window using location.replace

    Hello,
    See if this helps
    Code:
    <tr>								
        <td width="23%">
      	 <?php echo $some text; ?>
        </td>
        <td>
            <?php echo $add info; ?>? 
    	<?php 
    												
    	if ($_REQUEST["notice here"] == "2") {
    
    	?>									
    	<input type="checkbox" name="notice here" value="2" onClick="javascript:window.location.replace('example.php','title=title')" <?php if ($_REQUEST["notice here"] == "2") {echo "checked";} ?>> <-  (Problem hier!)
    	<?php
    									
    	} else {
    									
    	?>
    	<input type="checkbox" name="notice here" value="2" onchange="check(this)" <?php if ($_REQUEST["notice here"] == "2") {echo "checked";} ?>>
    	<?php
    									
    	}
    									
    	?>
       </td>								
    </tr>

Similar Threads

  1. To open a link from Google, I have to open in a new tab or window
    By Bindaas-ER in forum Technology & Internet
    Replies: 3
    Last Post: 07-03-2011, 04:02 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 - location.replace
    By Cordaro in forum Software Development
    Replies: 6
    Last Post: 13-05-2010, 11:55 PM
  4. How to Open Popup Window in Javascript?
    By Soumen in forum Software Development
    Replies: 4
    Last Post: 07-02-2010, 04:02 AM
  5. Can't open a link in new window in IE6
    By rupak in forum Technology & Internet
    Replies: 3
    Last Post: 12-01-2009, 06:11 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,221,067.47139 seconds with 17 queries