Skip to main content
Inspiring
June 2, 2012
Answered

CS6 hyperlink problem

  • June 2, 2012
  • 13 replies
  • 70385 views

Hi everyone,

 

In Indesign CS6, I created a new URL hyperlink and pasted the following link into the field:

http://law.ato.gov.au/atolaw/view.htm?docid=AID/AID2004688/00001

But when I click OK and then look in the URL field in the hyperlinks panel, I see that Indesign has changed the link to the following:

http://law.ato.gov.au/atolaw/view.htm%3Fdocid%3DAID/AID2004688/00001

Notice how it's swapping out the question mark (?) after .htm with %3F.

It's also swapping out the equals sign (=) with %3D.

This breaks the URL and makes it no longer workable.

I tried reinstalling Indesign but the problem still remains.

I wondered if anyone knows why this is happening and whether there's a workaround?

Appreciate any help.

    This topic has been closed for replies.
    Correct answer Laubender

    @gwhPoster – That seems to be an encoding problem. Do you use a prerelease beta version of InDesign CS6?

     

    Background:
    It seems that every URL that is filled in in the Hyperlink palette is encoded with something like encodeURI() (a global ExtendScript function):

    string encodeURI (text: string)

    Encodes a string after RFC2396.

    Create an UTF-8 ASCII encoded version of this string. The string is converted into UTF-8. Every non-alphanumeric character is encoded as a percent escape character of the form %xx, where xx is the hex value of the character. After the conversion to UTF-8 encoding and escaping, it is guaranteed that the string does not contain characters codes greater than 127. The list of characters not to be encoded is -_.!~*'();/?:@&=+$,#. The method returns false on errors.

     

    To get it back to a working URL we could decode it by "decodeURI()":

     

    string decodeURI (uri: string)

    Decodes a string created with encodeURI().

     

    To correct that you could use the following script (JavaScript).

    (After running the script don't go to "Hyperlink options…" in the Hyperlink panel and hit "OK" since the URL is converted back and you have to run the script again to correct that!)

     

    //DecodeURI_AllHyperlinks_DestinationURL_Name.jsx
    //DESCRIPTION:Decodes all hyperlink destination URLs and names; can be undone in one go!
    //Uwe Laubender
    
    /**
    
    * @@@BUILDINFO@@@ DecodeURI_AllHyperlinks_DestinationURL_Name.jsx !Version! Mon Jun 04 2012 14:48:49 GMT+0200
    
    */
    
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
    
    app.doScript
    (
    	_DecodeURI_AllHyperlinks_DestinationURL_Name , 
    	ScriptLanguage.JAVASCRIPT, 
    	[] , 
    	UndoModes.ENTIRE_SCRIPT, 
    	"Decode all hyperlink URLs and names"
    );
    
    
    function _DecodeURI_AllHyperlinks_DestinationURL_Name()
    {
    
    	var d = app.documents[0];
    	var allHyperlinks = d.hyperlinks;
    
    	for(var n=0;n<allHyperlinks.length;n++)
    	{
    
    		var newDestURL = decodeURI( allHyperlinks[n].destination.destinationURL );
    		var newDestName = decodeURI( allHyperlinks[n].destination.name );
    
    		allHyperlinks[n].destination.destinationURL = newDestURL;
    
    		try{
    		allHyperlinks[n].destination.name = newDestName;
    		}catch(e){};
    
    	};
    
    }; //END function "_DecodeURI_AllHyperlinks_DestinationURL_Name()"
    

     

    Hope that helps.

    Uwe

     

    IMPORTANT NOTE:

    The code above was damaged before. Why? This happened at the end of 2019 when this thread was moved over from the old InDesign forum to this new InDesign forum. A lot of script code from a lot of threads were affected back then. I corrected the code now.

     

    Regards,
    Uwe Laubender

    ( ACP )

    13 replies

    Known Participant
    July 6, 2012

    This does the same thing for me Just got CS6...so "advanced" it's got werid bugs that were never there before...grrrr!!! Very annoyed with Adobe right now. How do I report a bug?

    Community Expert
    July 6, 2012

    How do I report a bug?

    @Aussie_leah – go there:

    https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

    But do not expect Adobe answering…

    Uwe

    Participant
    June 6, 2012

    Hi,

    I was struggling with the same problem but was able to make it work by opening the Hyperlinks panel and manually amending the characters in the URL field (i.e. delete "%3F", key in "?"). Seems to publish to PDF with no issues. Hope that helps!

    Community Expert
    June 6, 2012

    @skim-creative – try out my script. It will change all hyperlink URLs and hyperlink names. You can undo the action in one go if you like…

    Uwe

    Participant
    June 27, 2012

    Hi

    I tried your script. I.e I copied the text to a text editor and saved as a .jsx file and placed within the script folder. When I ran it it gave an error number 14, no matching closing brace found?

    Cheers Nigel

    LaubenderCommunity ExpertCorrect answer
    Community Expert
    June 4, 2012

    @gwhPoster – That seems to be an encoding problem. Do you use a prerelease beta version of InDesign CS6?

     

    Background:
    It seems that every URL that is filled in in the Hyperlink palette is encoded with something like encodeURI() (a global ExtendScript function):

    string encodeURI (text: string)

    Encodes a string after RFC2396.

    Create an UTF-8 ASCII encoded version of this string. The string is converted into UTF-8. Every non-alphanumeric character is encoded as a percent escape character of the form %xx, where xx is the hex value of the character. After the conversion to UTF-8 encoding and escaping, it is guaranteed that the string does not contain characters codes greater than 127. The list of characters not to be encoded is -_.!~*'();/?:@&=+$,#. The method returns false on errors.

     

    To get it back to a working URL we could decode it by "decodeURI()":

     

    string decodeURI (uri: string)

    Decodes a string created with encodeURI().

     

    To correct that you could use the following script (JavaScript).

    (After running the script don't go to "Hyperlink options…" in the Hyperlink panel and hit "OK" since the URL is converted back and you have to run the script again to correct that!)

     

    //DecodeURI_AllHyperlinks_DestinationURL_Name.jsx
    //DESCRIPTION:Decodes all hyperlink destination URLs and names; can be undone in one go!
    //Uwe Laubender
    
    /**
    
    * @@@BUILDINFO@@@ DecodeURI_AllHyperlinks_DestinationURL_Name.jsx !Version! Mon Jun 04 2012 14:48:49 GMT+0200
    
    */
    
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
    
    app.doScript
    (
    	_DecodeURI_AllHyperlinks_DestinationURL_Name , 
    	ScriptLanguage.JAVASCRIPT, 
    	[] , 
    	UndoModes.ENTIRE_SCRIPT, 
    	"Decode all hyperlink URLs and names"
    );
    
    
    function _DecodeURI_AllHyperlinks_DestinationURL_Name()
    {
    
    	var d = app.documents[0];
    	var allHyperlinks = d.hyperlinks;
    
    	for(var n=0;n<allHyperlinks.length;n++)
    	{
    
    		var newDestURL = decodeURI( allHyperlinks[n].destination.destinationURL );
    		var newDestName = decodeURI( allHyperlinks[n].destination.name );
    
    		allHyperlinks[n].destination.destinationURL = newDestURL;
    
    		try{
    		allHyperlinks[n].destination.name = newDestName;
    		}catch(e){};
    
    	};
    
    }; //END function "_DecodeURI_AllHyperlinks_DestinationURL_Name()"
    

     

    Hope that helps.

    Uwe

     

    IMPORTANT NOTE:

    The code above was damaged before. Why? This happened at the end of 2019 when this thread was moved over from the old InDesign forum to this new InDesign forum. A lot of script code from a lot of threads were affected back then. I corrected the code now.

     

    Regards,
    Uwe Laubender

    ( ACP )

    November 1, 2012

    Hi I tried running the script but it threw up this error:

    I think it's maybe beause my link is a "Share to Twitter" and includes the text for the pre-written tweet.
    Where this link is 'breaking' is the first url character between "tweet" and "text". It should read "tweet?text" not "tweet%3Ftext".
    This is the only character that needs reverting. I'm asuming this kind of operation is too complex for a script?

    Participant
    November 6, 2012

    @Magic_monkey – thank you for the full URL.

    If I run the the full URL with the snippet and copy it from the ESTK Console to my browser it seems to work:


    Don't know why it does not work within InDesign CS6.
    Cannot test that right now…

    Uwe


    I found Uwe Laubender's script fails if you have internal links in your indd file. I made some enhancements to the script and pulled out the undo structure since I figured I could just save the doc under a new name if I was worried about it.

    I also added console messages listing the updates, and added a success message at the end to give some comfort that things worked okay.

    If you have external doc reference links, this script will fail since it loses context once the externally referenced document comes up. You can look at the console messages to determine which link is the problem - I've found the script processes the links from the bottom up when you compare it to the links in the hyperlink panel.

    With this script, I'm able to keep using CS6 ... I'm not so surprised a bug like this crept into InDesign CS6, what surprises me more is the product's now 6 months old and something this fundamental has still not been fixed.

    //DecodeURI_AllHyperlinks_2.jsx

    //DESCRIPTION:Decodes all hyperlink destination URLs and names

    //Uwe Laubender - enhanced by Joe Fugate

    var d = app.documents[0];

    var allHyperlinks = d.hyperlinks;

    var totalLinks = allHyperlinks.length;

    var repairedLinks = 0;

    for(var n=0;n<allHyperlinks.length;n++){

       

        if ("documentPath" in allHyperlinks.destination) {

            var docPath = allHyperlinks.destination.documentPath;

            var linkName = allHyperlinks.name;

            $.writeln("Link " + n + ": " + linkName + ": URL: " + docPath + " external link");

            continue;

        };

       

        if ("destinationURL" in allHyperlinks.destination) {

            repairedLinks = repairedLinks + 1;

            var linkName = allHyperlinks.name;

            var newDestURL = decodeURI(allHyperlinks.destination.destinationURL);

            var newDestName = decodeURI(allHyperlinks.destination.name);

       

            allHyperlinks.destination.destinationURL = newDestURL;

            try{

                allHyperlinks.destination.name = newDestName;

            }catch(e){};

           

            $.writeln("Link " + n + ": " + linkName + ": URL: " + newDestURL + " repaired");

           

        } else {$.writeln("Link " + n + ": " + linkName + ": Not a URL link");};

    };

    alert("Successfully repaired "+ repairedLinks + " URLs");