[Pro] Javascript for Search Field, Safari problems

Walter,

Thank you for the information about JS placement in light of how things have changed.

By the way, I was able to resolve the IE problem where the field wouldn’t get reset when the user clicks the BACK button from the Results page. While strange, my revised code works…

BEFORE (bad):

//clear & defocus search field after press of browser Back button on Results page
//(works in FF, Chrome & Safari, but not IE or Edge)
function pageShown(evt){
    if (evt.persisted){
        document.getElementById("Field").blur();
    } 
}
window.addEventListener("pageshow", pageShown, false);

AFTER (good):

//clear & defocus search field after press of browser Back button on Results page
//(works in FF, Chrome & Safari, but not IE or Edge)
function pageShown(evt){
    if (evt.persisted){
        document.getElementById("Field").blur();
    } else { document.getElementById("Field").value = ""; document.getElementById("Field").blur();}
}
window.addEventListener("pageshow", pageShown, false);

I tried it without the “if” statement at all, but that didn’t work. The addition of the “else” works. And I found that “blur();” needs to be in the “if” and both “blur();” and “value=‘’;” needs to be in the else. Confirmed in Edge(Win10), IE11(Win10), IE9(Visa), as well as Chrome and Firefox on Mac and Windows, as well as Safari, and iOS Safari, and FF on Android.

My code can now be placed before without need for “window.onload” and it JustWorks.

Thanks again, for all your advice.

Sincerely,

James W.


dynamo mailing list
email@hidden
Update your subscriptions at: