Copy link to clipboard
Copied
Hi!
Is there a script command that I can use to change hyperlinks of a document to just regular text?
Thanks!
var gDoc = app.activeDocument;
RemoveHyperLinks();
function RemoveHyperLinks() {
if (gDoc.hyperlinks.length > 0){
for (var i = gDoc.hyperlinks.length-1; i >= 0; i--) {
gDoc.hyperlinks.remove();
}
}
}
Copy link to clipboard
Copied
var gDoc = app.activeDocument;
RemoveHyperLinks();
function RemoveHyperLinks() {
if (gDoc.hyperlinks.length > 0){
for (var i = gDoc.hyperlinks.length-1; i >= 0; i--) {
gDoc.hyperlinks.remove();
}
}
}
Copy link to clipboard
Copied
Why not just:
app.activeDocument.hyperlinks.everyItem().remove()
Copy link to clipboard
Copied
Wow, it was that simple! Thanks guys!
Copy link to clipboard
Copied
IIRC, you need to remove the hyperlink source and hyperlink destination as well...
Harbs
Copy link to clipboard
Copied
Hi Harbs!
It doesn't remove those as well? Is that why when I try to turn them back to hyperlinks, it does not work? How do I go about doing that? Thanks.
Copy link to clipboard
Copied
It depends what you are trying to do.
If you used text sources and destinations and you want to remove them all, this should do the job:
app.activeDocument.hyperlinkTextDestinations.everyItem().remove()
app.activeDocument.hyperlinkTextSources.everyItem().remove()
Otherwise, you'd want to loop through the hyperlinks and remove the destinations and sources as you go...
Harbs
Copy link to clipboard
Copied
Thanks Harbs!
Yes, I did use text sources and destinations. Now I can remove the hyperlinks and create them again with no problem at all!
Thanks again, guys!
Copy link to clipboard
Copied
Thank you, Harbs!
Your script has enabled me to strip out problematic hyperlinks imported from Word. After numerous unsuccessful attempts, I can now successfully export the document to epub.
I am most grateful.
Marie
Copy link to clipboard
Copied
Hi Harbs,
I've encountered this issue in a document but am not familiar with scripting. How would I use these lines?
app.activeDocument.hyperlinkTextDestinations.everyItem().remove()
app.activeDocument.hyperlinkTextSources.everyItem().remove()
A thousand thank you's!
Amanda
Copy link to clipboard
Copied
Simply run this script:
app.activeDocument.hyperlinks.everyItem().remove();
app.activeDocument.hyperlinkTextDestinations.everyItem().remove();
app.activeDocument.hyperlinkTextSources.everyItem().remove();
It deletes all hyperlinks, text anchors (destinations) and text sources.
— Kas
Copy link to clipboard
Copied
I realise this is an old thread, but people (like myself) stumble onto these things when Googling for answers, so I thought it worth adding to the answers here…
It's not always necessary to delete every object (hyperlink, source and destination) in order to completely remove a hyperlink. In fact, if you're trying to remove individual hyperlinks this way, you'll most likely end up trying to access non-existing objects and crash your script.
The short answer is, removing the `hyperlinkTextSource` object is, in most cases, all you need to do. For a more in-depth answer, see my answer on Stack Overflow.