javascript - Replace any words in URL -
i need replace 2 words in window.location.href
when user wants follow it.
for example i'm user , want go url: stackoverflow.com/questions/7821801/javascript-indexof
need replace '7821801'
'js'
, '-indexof'
'ok'
when page loads.
or redirect user 'mysite.com/css'
'mysite.com'
.
i tried
window.onload = function() { var urli = window.location.href; var arr = ['acasa', 'sktop']; (var = 0; <= arr.length; i++) { if (urli.search(arr[i]) > 0) { document.getelementbyid('parv').innerhtml = urli.replace(arr[i], 'tek'); }; }; }
but did not work.
if want redirect user, should write window.location.href=document.getelementbyid('parv').innerhtml;
after manipulations
by way, if want redirect, there no need in setting new url dom element, use variable
Comments
Post a Comment