Featured post
javascript - Rewriting one part of a URL into a link -
i trying 1 part of url insert another.
url in address bar read domain.com/test.php?/12345 link in page must become domain.com/do/login/12345 (this end number change every user)
(note can't change url domain.com/test.php?/12345 has been set site owner.)
for urls above had remove http://www. part above new user can't submit more 1 link spam prevention. final script should include http://www.
you able see need number @ end ie 12345 i'm not sure how achieve (javascript beginner). have far:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>path test</title> </head> <body> <script> // url eg http://www.domain.com/test.php?/12345 newurl = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname; </script> <script> //write new domain add user number ie 12345 document.write('http://www.domain.com/do/login/' + window.location.pathname); </script> </body> </html>
this not work shows got to.
i've had luck using script found @ http://www.sitepoint.com/forums/showthread.php?t=244955 worked filenames extension name on .html, .php etc.
any ideas?
thanks in advance.
first, need part of url after question mark. available in the
window.location.search
variable. note that includes "/". need create actual link. document.write('http://...) won't work because write in text form , not actual anchor tag. need like:
document.getelementbyid("yourlink").href = "http://domain.com/do/login" + window.location.search
don't forget put anchor tag in html id matches element in getelementbyid() method above. if don't want put anchor tag in html markup, can create 1 javascript like:
var link = document.createelement('a'); link.href = "http://domain.com/do/login" + window.location.search; document.body.appendchild(link);
this may need further adjusting needs.
- Get link
- X
- Other Apps
Comments
Post a Comment