Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

ie7 focus() nach ajax update

Empfohlene Antworten

Veröffentlicht

Ich habe aktuell ein kurioses Problem. Ich will nach einem Ajax-Update eines Seitenbereichs einem Textfeld den Fokus geben.

Ich habe es via document.getElementById('meineId').focus() probiert und zusätzlich über jQuery('#meineId').focus().

Nur IE7 scheint dies zu ignorieren (IE6 und 8 sind hier netter). Wenn ich mir nach dem Request document.activeElement.id ausgeben lassen, so bekomme ich mein body-Element.

Wenn ich vor dem Aufruf von focus() mir etwas mit alert() ausgeben lasse, dann wird der Fokus allerdings gesetzt.

Hat jemand von euch schon mal etwas ähnliches erlebt?

Ich würde gern ein Beispiel posten, aber dafür müsste ich erst eines konstruieren (da die Anwendung auf JSF/Facelets aufsetzt). Ich hoffe meine verbale Beschreibung führt zum Erfolg, sonst erstelle ich noch ein Beispiel.

Dein Problem ist es das du versuchst einen Focus zu setzen obwohl das Feld noch nicht existiert. Was du daran erkennen kannst weil es ja funktioniert wenn du ein Alert davor setzt.

Kannst du zbsp mit einem timeout umgehn. aber das is auch nicht 100% sicher das es dann immer und ueberall geht. Kommt halt auch auf die Rechnerleistung an :C

Aber wie du das nun ordentlich umgehn kannst faellt mir leider grade keine saubere loesung zu ein :/

Ted

Ich kenne es von Prototype, das man ein onSuccess Event hat.

Gibt es soetwas bei jQuery eventuell auch? Dann könnte man dort

den Focus setzen.

Bitte nicht steinigen, falls es dies nicht bei jQuery nicht gibt.

  • Autor

Der Ablauf des Ajax-Updates:

1. Event durch User ausgelöst

2. Ajax-Update auslösen

3. oncomplete (entspricht onSuccess) soll den Focus setzen (also nach dem Update des DOM-Trees)

Mit einem Timeout hatte ich es auch schon versucht, allerdings ohne Erfolg.

  • Autor

Nach der Beschreibung unter activeElement Property (document, HTMLDocument Constructor) hatte ich auch schon festgestellt, dass ich als aktives Element das body-Element erhalte. Deswegen kam ich auf die Idee auch mal setActive() zu benutzen. Et voilà, es funktioniert:


oncomplete="x = document.getElementById('<IdDesElementsDasDenFokusErhaltenSoll>'); try{x.setActive();} catch(e) {}; x.focus();"

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.