adding substring

i have some urls, i want to change the path on click by adding a substring (/myfolder/) in the path.
for eg,  http://www.time.com/time/magazine  should become  http://www.time.com/myfolder/time/magazine
pl suggest.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>  
<script>
$(document).ready(function() {
	$(function() {	
			$("a").click(function() {
				if (($(this).attr("href").indexOf("time.com") >= 0)) {				
				var t =  $(this).attr("href");
				alert(t);
				var t1 = ($(this).attr("href")).substr(0, 18);
				alert (t1);
				var lin ='/myfolder/'
				($(this).attr("href")) =   t1+ lin + t; 
				return false;
				}
			});
		}
	});
});
</script>
</head>
<body>
<a href="http://www.time.com/time/magazine">mag</a> <br />
<a href="http://www.time.com/time/people">people</a> <br />
<a href="http://www.time.com/time/nation">nation</a>
</body>
</html>

Open in new window

yingwhoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
you should be doing this at load time, not upon click. Otherwise on every click of the same link you would be trying to add /myfolder over and over. try:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>  
<script>
$(document).ready(function() { 
	   	$('a').each(function(){
			this.href = this.href.replace(/time\.com/,'time.com/myfolder')
			
		});
});
</script>
</head>
<body>
<a href="http://www.time.com/time/magazine">mag</a> <br />
<a href="http://www.time.com/time/people">people</a> <br />
<a href="http://www.time.com/time/nation">nation</a>
</body>
</html>

Open in new window

0
yingwhoAuthor Commented:
heilo

thanks.
1 problem
its doing  time 2 times.. so let me change my question as below..

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>  
<script>
$(document).ready(function() {
                $('a').each(function(){
                        this.href = this.href.replace(/time\.com/,'time.com/myfolder')
                       
                });
});
</script>
</head>
<body>
<a href="http://www.time.com/magazine">mag</a> <br />
<a href="http://www.time.com/people">people</a> <br />
<a href="http://www.time.com/nation">nation</a>
</body>
</html>

please make  http://www.time.com/magazine to  http://www.time.com/myfolder/magazine etc
0
hieloCommented:
what you posted already gives the result you seek, try it:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>  
<script>
$(document).ready(function() {
                $('a').each(function(){
                        this.href = this.href.replace(/time\.com/,'time.com/myfolder')
                       alert(this.href)
                });
});
</script>
</head>
<body>
<a href="http://www.time.com/magazine">mag</a> <br />
<a href="http://www.time.com/people">people</a> <br />
<a href="http://www.time.com/nation">nation</a>
</body>
</html>


If you want the result to include time.com/time/myfolder then use:
this.href = this.href.replace(/time\.com/,'time.com/time/myfolder')

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yingwhoAuthor Commented:
great. thanks
0
yingwhoAuthor Commented:
hielo.. u have written lot of tricky scripts and impressed me..
if u can solve my trickiest problem below i will be flat!
this Q is around for a while with 10 answers already, but still not usable.

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_26117631.html
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.