Forum Moderators: open

Message Too Old, No Replies

Redirect url with javascript

Redirect url with javascript

         

xbl01234

8:26 am on Sep 15, 2007 (gmt 0)

10+ Year Member



Hello;
I got a problem with using redirect url with javascript. Could anyone help, please.


<html>
<head>
<script type="text/javascript">
function myFuction(char){
setTimeout('window.location="../country/"' + 'char',3000)
}
</script>
</head>

<button id="b2" onClick="myFuction('2')"> 2 </button>
</html>

daveVk

8:51 am on Sep 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



setTimeout('window.location="../country/' + char + '";',3000);

maybe?

xbl01234

9:53 am on Sep 15, 2007 (gmt 0)

10+ Year Member



it still does not work.

i have wrote a rewriteRule in .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^/]+)/([^/]+)/$ display.php?name1=$1&name2=$2 [L]

daveVk

11:41 am on Sep 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What url do you expect button 2 to load in this example?

xbl01234

11:50 am on Sep 15, 2007 (gmt 0)

10+ Year Member



like the url as following;
[wmysite.com...]

and i tested my rewriteRule, it works well
for the following

<a href="/country/2/"> testing </a>

daveVk

12:31 pm on Sep 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



setTimeout('window.location="/country/' + char + '/";',3000);

with trailing slash and without leading ..?

xbl01234

1:00 pm on Sep 15, 2007 (gmt 0)

10+ Year Member



your one look fine for me, but it still does not open a window, i don't known why.

and i rechange my code as following, and it works fine now. Thanks for your time.


<script type="text/javascript">
var char; // global variable
function myFunction(str) {
char=str;
window.setTimeout("delayit()", 3000);
}
function delayit() {
alert(char);
window.location.href = "/country/" + char + "/";
}

</script>

daveVk

2:07 pm on Sep 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This bit string is put together after the timeout.

'window.location="/country/' + char + '/";'

by making char global you solved the problem.

regards

xbl01234

9:35 pm on Sep 15, 2007 (gmt 0)

10+ Year Member



Thanks daveVk;
it works now.