Jump to content

Change form document.write to innerHTML


Recommended Posts

Wow.  Am getting a bit confused.  We have a script that where if a field value is NOT blank it displays an icon on the screen.   The field contains a URL link to a webpage elsewhere in our app.   The icon is just a PNG file  (the img scr in script below) which is itself clickable to the web-link URL that is the contents of the field (the field will always contain a URL value - or not).  It has functioned fine for a couple of years now

Our (old) Script is as follows:

<script>
if ('[@field:XXXX]' != '') {
document.write('<a href="[@field:XXXX]" target="_blank">   <img src="../resources/File_icon_INS.png" alt="Files" height="40" width="40" /></a>');
}
</script>

We know we need to change it with the new async deploy code and to replace the document.write part with innerHTML.  However what we have tried has not worked.  Would love it if a kind person could help us out.  Thanks :-)

 

 

Link to comment
Share on other sites

Hi @georgep,

You can try using the following code:

<div id="icon"></div>
<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {
if ('[@field:XXXX]' != '') {
document.getElementById("icon").innerHTML='<a href="[@field:XXXX]" target="_blank">   <img src="../resources/File_icon_INS.png" alt="Files" height="40" width="40" /></a>';
}   
});
</script>

Hope this helps.

Link to comment
Share on other sites

  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...