The best place to *find* answers to programming/development questions, imo, however it's the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but again, a great reference for *finding* answers.

My Music (Nickleus)

20130315

sahi - how to replace the domain of a url

in our company's application we send out an email asking users to confirm their new membership application by clicking on a link:
http://prod.mycompany.com/MembershipApplication/validateMembershipApplication?id=9354&email=me@example.com

but when i'm testing this usecase in sahi, i don't want to click on a production link, i want to use a link on my test server:
http://localhost/MembershipApplication/validateMembershipApplication?id=9354&email=me@example.com

so here's how i replace the prod link with localhost:
#######################

var $prod_url;

// ... more code ...

_set($prod_url, _link(/http:\/\/prod\.mycompany\.com\/MembershipApplication\/validateMembershipApplication\?id=.*/).href);
 

_call(window.open($prod_url.split("http://prod.mycompany.com").join("http://localhost")));

#######################

this code identifies a link that matches the regex below and returns the url ( .href ):

_link(/http:\/\/prod\.mycompany\.com\/MembershipApplication\/validateMembershipApplication\?id=.*/).href


thanks to the post Javascript - how to replace a sub-string? for the replace code :)

No comments:

Post a Comment