First Question:

There are two images that needed to be rendered in Salesforce Marketing Cloud based on where they're being viewed from (Smartphone device or desktop).

I wrote a script in HTML file in a content block, which will return an image (refered by ContentBlockbyKey) if displayed from a mobile device or else another image if displayed from desktop. However, image is not being rendered:

Here is the code:

<!DOCTYPE html>
 <title>Mobile Test</title>

 <p id="text"></p>

 <script type="text/javascript">
  var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
  var element = document.getElementById('text');
  if (isMobile) {
  } else {

Second Question:

Is it possible to know which device is the email being viewed from using Ampscript?

  • 3
    This is a css question and belongs on Stack Overflow as this is unrelated to SalesForce Sep 21, 2019 at 23:40
  • @Gortonington - thank you, i'll post it there.
    – Nat Fan
    Sep 21, 2019 at 23:46
  • @Gortonington - i've updated my question, please review and comment.
    – Nat Fan
    Sep 23, 2019 at 21:20

1 Answer 1


AMPscript and SSJS are both server-side meaning they are run and processed prior to the email being sent. Anything 'client-side' would have to be done via CSS or 'live images' such as Movable ink or Live Clicker.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .