yingwho
asked on
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.
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>
ASKER
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\.c om/,'time. com/myfold er')
});
});
</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
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\.c
});
});
</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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
great. thanks
ASKER
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.
https://www.experts-exchange.com/questions/26117631/popup-communication.html
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.
https://www.experts-exchange.com/questions/26117631/popup-communication.html
Open in new window