3

I'm working on a "Mobile Web" app, and relying completely on javascript to solve this problem. On certain Android devices, most notably the Samsung Galaxy family, a window.resize event fires when the soft keyboard appears, shortening the height of my screen.height. When a user taps the "Go" button of the soft keyboard, my app reloads with a height that is less the height of the soft keyboard.

Now, I am listening to the window.resize event, so if the user rotates the device, everything will right itself. However, I'm hoping to figure out a way to fire off the window.resize event programmatically, so that every action performed when I rotate the device is triggered.

Can this be done?

elrasguno
  • 229
  • 3
  • 5

2 Answers2

0

I had this same problem and abandoned trying to fire the events and went with modifying the meta viewport after keyboard has gone. See answer here: https://stackoverflow.com/a/11321889/1500269

Community
  • 1
  • 1
Citizen
  • 83
  • 1
  • 9
0

if you're using jQuery mobile use jQuery trigger()

if not use this code from a stackoverflow question:

You can use fireEvent on IE, and w3c's dispatchEvent on most other browsers. To create the event you want to fire, you can use either createEvent or createEventObject depending on the browser.

Here is a self-explanatory piece of code (from prototype) that fires an event dataavailable on an element:

    var event;
  if (document.createEvent) {
    event = document.createEvent("HTMLEvents");
    event.initEvent("dataavailable", true, true);
  } else {
    event = document.createEventObject();
    event.eventType = "ondataavailable";
  }

  event.eventName = eventName;
  event.memo = memo || { };

  if (document.createEvent) {
    element.dispatchEvent(event);
  } else {
    element.fireEvent(event.eventType, event);
  }

Update:

There is a fireEvent() for IE and dispatchEvent() method for non IE browser. You can manually fire your events. The trick is to create an event just like window.resize and fire that. I never tried this. But I hope that can help.

Community
  • 1
  • 1
Mohsen
  • 64,437
  • 34
  • 159
  • 186
  • Mohsen, I tried this but it didn't solve the issue. If I could fire the same event that's fired by the browser with this technique, that would help, but I don't know how to do that yet. – elrasguno Aug 09 '11 at 21:59
  • Are you using jQuery there? if yes, you just need to write $(window).trigger('close'); – Mohsen Aug 09 '11 at 22:21