Safari Mac OSX Backspace Issues

Is there anyone out there who knows how to handle the behavior of Safari Web Browser that sets the current page to the previous page whenever users were pressing backspace key? I'm currently experiencing this issue on Mac OSX Lion 10.7.2 and a silverlight application whenever our users were trying to correct fields using the backspace/Delete key.


I've had this problem in the past too. I spent a good week or so trying to come up with a solution, and eventually the best way to work around this problem (I never found a "fix" so to speak) was the following:

  • Suspend all of the backspace key down events using Javascript. Don't allow any backspace events to reach the Silverlight container. This will mean that Silverlight never takes you to the previous page any more, but you also won't be able to delete any text in a text field! Point 2 explains how to work around this.

  • Attach a KeyUp event handler to the RootVisual of your Silverlight control. KeyEventArgs ' original source is a TextField and the key itself was Key.Back , then we must delete some text inside of the textbox manually. We do this by looking at the TextBox's SelectionStart and SelectionLength properties. SelectionStart gives you the location you want to delete from, and SelectionLength gives you how many characters you want to delete. Finally, you need to work out the correct location of where the cursor should be now. This should just be equal to the SelectionStart property's value.

  • There is a flaw with this approach. Because we have to manually listen to KeyUp events, the Key.Back KeyUp event is only fired when the backspace key is released. This means that if you are using Safari and hold backspace down, only one character will be deleted. You will need to release backspace and press it again to delete another character. This is a small price to pay in my opinion though, considering the alternatives are to view the previous page or not handle backspace at all!

    It's worth noting that all of this can be Mac/Safari specific. You can use HtmlPage.BrowserInformation.UserAgent to find the browser type, and only attach the RootVisual_KeyUp handler if the browser is Safari. If you only suspend backspace events in javascript in Safari too, this will only have an effect in Mac/Safari, and keep the default functionality for every other browser.

    Good Luck! Hope this helps!

    链接地址: http://www.djcxy.com/p/63118.html

    上一篇: 在山狮子上的Safari 6.0.2上的阴影

    下一篇: Safari Mac OSX Backspace问题