in5 Answers archive · asked 2022-09-16 · 1 answer

Broken JS script call from links (<a href="javascript:callMyScript()".....)

javascripthyperlinks

Dear in5 team,

By upgrading to in5-3.8.10 have noticed, that HyperLinks defined from Indesign throw an error at iOS Safari.

Example of link, exported from InDesign via IN5.

<a href="#">

        <div alt="">&nbsp;</div>

      </a>

I suppose, you need to ask IN5 developers, to adjust function definition from "assets/js/in5.config.js" to strip "javascript:" prior call strict function like:

function strfunc(str,cthis){

if(!str || !str.length){ return; }

if(cthis){ str = str.replace(/this\)/g, '$(\'[data-uid="'+getUID(cthis)+'"]\')[0])'); }

str.replace(/;$/,'').split(';').forEach(function(s){

    s = s.replace("javascript:", "");

   try{ return Function('"use strict";return ('+s+')')(); }

   catch(err){console.log('strfunc error running: '+s+'\r>>>'+err)}

   }) 

}

 

in5 user · 2022-09-16 · 2,464 views

1 answer

Thank you for sending the code over. We will have a developer take a look.

in5 team · 2022-09-16

Here's the information I got from our developer about what sounds like the same issue with hyperlinks:

They said that there's in issue in the openLink function in in5.config.js. In other browsers the JavaScript action from the link is handled automatically, however in iOS, the openLink function is called to "deal w buggy ios propagation". The openLink function then passes the js action to strfunc, however the javascript: part of the string is not removed which throws an error in strfunc.
Here's how the function looks in 3.8.10:
function openLink($a,e){
    var href=$a.attr('href'), w;
    if(href.indexOf('javascript:')===0){strfunc(href,$a[0]); w=!0;}
    else { w = window.open(href,$a.attr('target')||'_blank'); }
    if(e && w){ e.preventDefault(); }
}
You can modify the function above to remove the javascript: part of the string as follows:
function openLink($a,e){
    var href=$a.attr('href'), w;
    if(href.indexOf('javascript:')===0){strfunc(href.substring("javascript:".length),$a[0]); w=!0;} <--- MODIFIED LINE
    else { w = window.open(href,$a.attr('target')||'_blank'); }
    if(e && w){ e.preventDefault(); }
}
To modify the code yourself, you can do the following:
  1. Open the in5.config.js file in a text editor such as TextEdit (macOS) or Notepad (Windows) or in an IDE such as Dreamweaver which is available if you have the full Adobe Creative Cloud subscription.
  2. Search for the function: 
    function openLink($a,e){
  3. Copy the modified code that includes the yellow highlighted line that was added.
  4. Replace the code in the in5.config.js file.
  5. Save the changes.
The fix will be applied in5 version 3.8.11, but we currently don't have an ETA on when that will be released.

in5 team · 2022-09-27

Was this useful?