-
Notifications
You must be signed in to change notification settings - Fork 33
Using a clicked link as an argument for a URL
Sander Ronde edited this page Feb 7, 2021
·
2 revisions
A common use case seems to be the pasting of URLs of links into another URL and opening that. For example having a right-click menu entry that, when clicked on a link, opens that link in google cache. In this tutorial you can see an example of how to do this.
- First of all create a new script-type menu item
- Select only the link-type content type, such that the right-click menu entry only shows up when clicking links.
- Paste in the following script
var target = crmAPI.contextData.target; // Get the clicked element
if (!target) { // Make sure it exists, if it doesn't, show an alert
alert('No target selected');
return;
}
// Find the closest link to what was clicked
var currentElement = target;
while (currentElement && !currentElement.href) {
currentElement = currentElement.parentNode;
}
// If we selected a link, open the new URL with the
// link target pasted in
if (currentElement && currentElement.href) {
// Change the URL below to point to your preferred URL
window.open(`http://example.com/?url=${currentElement.href}`, '_blank');
} else {
// If nothing was selected, show an alert
alert('Target is not a link!');
}
- Modify the URL (currently
http://example.com/?url=
) to be the one you want to point to. - You're done! Save the script and try it out.