Matthias Scharwies: Ausblick auf 2022: window.alert('Hallo Welt') geht nicht mehr?

Beitrag lesen

Servus!

Hallo Robert,

was sollen denn die (leichtgewichtigen) Alternativen zu prompt oder confirm sein?

evtl. das Dialog-Element. Dann bleiben zwar Firefox und Safari draußen vor, aber das ist ja vielleicht so gewünscht.

Nein, alles in JavaScript.

Chris Coyier erwähnt JavaScript/Window/postMessage

What we’ve been told so far, the solution is to use postMessage if you really absolutely need to keep this functionality for cross-origin iframes. That sends the string the user uses in window.alert up to the parent page and triggers the alert from there. I’m not the biggest fan here, because:

  • postMessage is not blocking like JavaScript dialogs are. This changes application flow.
  • I have to inject code into users code for this. This is new technical debt and it can harm the expectations of expected user output (e.g. an extra <script> in their HTML has weird implications, like changing what :nth-child and friends select).
  • I’m generally concerned about passing anything user-generated to a parent to execute. I’m sure there are theoretical ways to do it safely, but XSS attack vectors are always surprising in their ingenouity.

Als zweites wird console.log()genannt. Damit habe ich im Wiki die meisten Live-Beispiele mit einer Ergebnisausgabe realisiert.

Herzliche Grüße

Matthias Scharwies

--
Einfach mal was von der ToDo-Liste auf die Was-Solls-Liste setzen.“