xbl1 Posted September 15, 2007 Share Posted September 15, 2007 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> Link to comment Share on other sites More sharing options...
Synook Posted September 15, 2007 Share Posted September 15, 2007 That function will relocate you to ../country/char (but it has syntax error fixed below). To use the char variable, you can't have quotes around it. <html><head><script type="text/javascript">function myFuction(char){setTimeout('window.location="../country/' + char + '"',3000)}</script></head><body><button id="b2" onClick="myFuction('2')"> 2 </button></body></html> < Link to comment Share on other sites More sharing options...
xbl1 Posted September 15, 2007 Author Share Posted September 15, 2007 That function will relocate you to ../country/char (but it has syntax error fixed below). To use the char variable, you can't have quotes around it.<html><head><script type="text/javascript">function myFuction(char){setTimeout('window.location="../country/' + char + '"',3000)}</script></head><body><button id="b2" onClick="myFuction('2')"> 2 </button></body></html> < i don't known why it still does not work.At the .htaccess filei wrote a rewriteRule as following;RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^([^/]+)/([^/]+)/$ submit.php?name1=$1&name2=$2 [L] Link to comment Share on other sites More sharing options...
Synook Posted September 15, 2007 Share Posted September 15, 2007 What doesn't work? Does it open up a new window, but can't find the address, or does nothing happen when you click the button? Link to comment Share on other sites More sharing options...
xbl1 Posted September 15, 2007 Author Share Posted September 15, 2007 What doesn't work? Does it open up a new window, but can't find the address, or does nothing happen when you click the button?it does not open a new window.and i tested the following code for the rewriteRule, it does the job well.<a href="/country/2/"> testing </a>and the browser bring out of the "http://www.mysite/country/2/"and i changed the followingsetTimeout('window.location="../country/' + char + '"',3000) tosetTimeout('window.location="/country/' + char + '/' + '"',3000) but it also does not open a new window for me. Link to comment Share on other sites More sharing options...
Synook Posted September 15, 2007 Share Posted September 15, 2007 Oops sorry, I must be tired... the function won't open a new window, it should just redirect your browser. But it doesn't? Link to comment Share on other sites More sharing options...
xbl1 Posted September 15, 2007 Author Share Posted September 15, 2007 What doesn't work? Does it open up a new window, but can't find the address, or does nothing happen when you click the button?i changed my code as following;<html><head></head><body><script type="text/javascript">var char; // global variablefunction myFunction(char) {window.setTimeout("delayit()", 3000);}function delayit() {window.location.href = "../country/" + char;}</script><button id="b2" onClick="myFunction('2')"> 2 </button></body></html>it's better now, it bring out a window, and get the right content from a specify file.But the url from the address bar is not right, it give me the result like the following;http://www.mysite.com/country/undefined/it should be like the "http://www.mysite.com/country/2/"but i does known why? Link to comment Share on other sites More sharing options...
xbl1 Posted September 15, 2007 Author Share Posted September 15, 2007 Oops sorry, I must be tired... the function won't open a new window, it should just redirect your browser. But it doesn't?Thanks for your time, i solved the problem already.var char; // global variablefunction myFunction(str) {char=str;window.setTimeout("delayit()", 3000);}function delayit() {alert(char);window.location.href = "/country/" + char + "/";} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.