How to replace href using javascript regex in Firefox?
Posted
by
Andrei
on Stack Overflow
See other posts from Stack Overflow
or by Andrei
Published on 2011-01-12T20:18:11Z
Indexed on
2011/01/12
21:54 UTC
Read the original article
Hit count: 193
I try to change some links on a webpage using the following code for jQuery on Rails
$(function () {
$('#lesson a').live('click', function () {
$.getScript(this.href.replace(/^(http...[^\/]+)?\/+(.*)$/,'/ajax/\\$2'));
return false;
});
})
This trick works for Chrome and Safari, but fails (nothing happens on click) for Firefox and Opera. What can be wrong with the code?
EDIT1:
The webpage contains:
<div id="lesson">
<a href="/subj1">Subject 1</a>
...
</div>
On click, a browser (i.e. Firefox and Opera) should make an ajax-request of /ajax/subj1
.
© Stack Overflow or respective owner