blinks
03-27-2012, 01:46 AM
The following bit of javascript grabs a URL, checks whether it contains the string "abcjournals", and if so, replaces any subdomain before the "abcjournals" with "test.abcjournals". e.g. xyz.abcjournals becomes test.abcjournals.
<script type="text/javascript">
var loc = window.location.href;
if (loc.match(/abcjournals/)) {
loc = loc.replace(/[a-z]+\.abcjournals/, "test.abcjournals");
window.location.replace(loc);
}
/script>
The above code works successfully, except that the page refreshes in an endless loop. If I add a "break;" or "exit;" after the window.location.replace line, there is no endless loop, but the URL string doesn't get replaced as expected.
I've also tried using a "var i = 0;" adding "&& (i===0)" to the IF statement, and incrementing i within the IF statement; but again, the string doesn't get replaced as expected.
Any suggestions much appreciated!
<script type="text/javascript">
var loc = window.location.href;
if (loc.match(/abcjournals/)) {
loc = loc.replace(/[a-z]+\.abcjournals/, "test.abcjournals");
window.location.replace(loc);
}
/script>
The above code works successfully, except that the page refreshes in an endless loop. If I add a "break;" or "exit;" after the window.location.replace line, there is no endless loop, but the URL string doesn't get replaced as expected.
I've also tried using a "var i = 0;" adding "&& (i===0)" to the IF statement, and incrementing i within the IF statement; but again, the string doesn't get replaced as expected.
Any suggestions much appreciated!