Click here to Skip to main content
15,885,696 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I would like to create a bookmarklet where it takes the current URL and uses a portion of it in a new window

Take this URL "https://my.salesforce.com/**00Q0f00001C3prS**"
"https://outboundengine.my.salesforce.com/_ui/core/email/author/EmailAuthor?p2_lkid=**00Q0f00001C3prS**&isdtp=lt&template_id=00X0f000002FfMJEA0&new_template=1&retURL=https%3A%2F%--qbdialer.na63.visual.force.com%2Fapex%2Fis_close"

Where the new URL keeps the bolded text, replace the patch before it and appends the new url with &isdtp=lt&template_id=00X0f000002FfMJEA0&new_template=1&retURL=https%3A%2F%--qbdialer.na63.visual.force.com%2Fapex%2Fis_close

I tried the following javascript:window.location.href=location.href.replace(https://my.salesforce.com/, 'https://my.salesforce.com/_ui/core/email/author/EmailAuthor?p2_lkid=')+'&isdtp=lt&template_id=00X0f000002FfMJEA0&new_template=1&retURL=https%3A%2F%--qbdialer.na63.visual.force.com%2Fapex%';


What I have tried:

javascript:window.location.href=location.href.replace(https://my.salesforce.com/, 'https://my.salesforce.com/_ui/core/email/author/EmailAuthor?p2_lkid=')+'&isdtp=lt&template_id=00X0f000002FfMJEA0&new_template=1&retURL=https%3A%2F%2Foutboundengine--qbdialer.na63.visual.force.com%2Fapex%';
Posted
Updated 17-Aug-17 3:40am

1 solution

Try something like this:
javascript:window.location.href=window.location.href.replace(/^https:\/\/my\.salesforce\.com\/(.+)$/i, "https://outboundengine.my.salesforce.com/_ui/core/email/author/EmailAuthor?p2_lkid=$1&isdtp=lt&template_id=00X0f000002FfMJEA0&new_template=1&retURL=https%3A%2F%--qbdialer.na63.visual.force.com%2Fapex%2Fis_close");

Regular Expressions - JavaScript | MDN[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900