Git Product home page Git Product logo

Comments (5)

cristianofromagio avatar cristianofromagio commented on June 6, 2024 2

I went ahead and tried to reach the Contact page (archived version for reference) from the website in your signature, and indeed, said Contact form failed to submit on Safari.

Solving your issue specifically

If you just want to make this form work on Safari, change the id value on these image elements inside your form to something other than numbers:

<!-- find each one in the code, they are not grouped like this -->

<img style="position:absolute; opacity: 0;" src="./image/update/piezoModule.webp" align="center" id="1002" class="preview" alt="">
<img style="position:absolute; opacity: 0;" src="./image/update/probeModule.webp" align="center" id="1001" class="preview" alt="" title="">
<img style="position:absolute; opacity: 0;" src="./image/update/ModuleDuo.webp" align="center" id="1003" class="preview" alt="">

Notice their ids: id="1002", id="1001" and id="1003". Change them to something else that is not just an integer number, for example id="img1002", id="img1001" and id="img1003". Just that will solve this form specific problem. To understand why, read the explanation below.

Breaking down the issue

This is the error that appears on the console when we try to submit the form in Safari (here I'm using Webkit MiniBrowser on Windows, but should apply to Safari as well):

image

image

This is the related line in our script. Notice the problem is it can't find the name property because (allegedly) elements[k] is undefined.

In this piece of code, elements refers to form.elements a property that returns a HTMLFormControlsCollection. We can access an entry on this collection by an index, by its name attribute or by its id attribute.

You can access a particular form control in the returned collection by using either an index or the element's name or id attributes. ref.

When we try accessing it using elements[k].name, k is one of the HTMLFormControlsCollection keys we get by passing it through the Object.keys() function.

This is what we get on Firefox (left), Chromium (middle) and Safari (right) when we run this script in the page:

// `form` being the contact form

Object.keys(form.elements).map((k) => {
  console.log(k, form.elements[k]);
});

console.log(Object.keys(form.elements));

image

Notice that, apart from the difference in size of Object.keys(form.elements) in each one of them, in Safari the 1002, 1001 and 1003 key returns an undefined element because it tries to find the item in the HTMLFormControlsCollection by its id but because it is an integer it confuses it with an index. That is why changing the img element id to a string solves the problem in this case.

What can we do to fix this?

Although our specific issue is with an integer id acting as an index, the real issue is that image elements shouldn't even be returned in the HTMLFormControlsCollection.

  • Report the error "upstream" to Safari: the issue "form.elements should not contain image elements." is a known bug reported in the Safari bug-tracker. We can improve by contributing to it and reporting it further with examples and reproductible scenarios.
  • Improve our script to safe-guard these edge cases: at first glance, this issue should not be possible ("all form elements' keys should return a valid form element"), but as we just saw, this can break and halt the execution of our script. This could also solve other issues that might be related to this specific problem (#351, #425).

from learn-to-send-email-via-google-script-html-no-server.

nextron-microprobe avatar nextron-microprobe commented on June 6, 2024 2

from learn-to-send-email-via-google-script-html-no-server.

cristianofromagio avatar cristianofromagio commented on June 6, 2024

Do you have any console errors while running on Safari? Chrome on iOS (if I'm not mistaken) also runs WebKit under the hood (like Safari).

Do you have a reproducible code example or have it hosted online somewhere?

from learn-to-send-email-via-google-script-html-no-server.

nextron-microprobe avatar nextron-microprobe commented on June 6, 2024

from learn-to-send-email-via-google-script-html-no-server.

nextron-microprobe avatar nextron-microprobe commented on June 6, 2024

from learn-to-send-email-via-google-script-html-no-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.