ajax - javascript redirect & replace -


<script type = "text/javascript">     var r = window.location.href;     if (r.match(/#|%23/)) {         r = r.replace(/#|%23/gi, \"@num@\");         window.location.href = r;     } </script> 

this script redirect page , replace # symbols @num@ in url (don't ask why)...

i'm trying modify script doesn't replace "#" if @ end of url

example:

http://www.example.com/test.php?f=abc#def 

will become

http://www.example.com/test.php?f=abc@num@def 

but link:

http://www.example.com/test.php?f=abc#def# 

will become:

http://www.example.com/test.php?f=abc@num@def# 

use positive lookahead guarantee there @ least 1 more character:

/(#|%23)(?=.)/g 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -