# \[Pro\] Javascript for Search Field, Safari problems

**URL:** https://discourse.softpress.com/t/pro-javascript-for-search-field-safari-problems/23703
**Category:** Dynamo
**Created:** [February 24, 2017, 7:05am UTC](https://discourse.softpress.com/t/pro-javascript-for-search-field-safari-problems/23703 "2017-02-24T07:05:31Z")
**Posts on this page:** 1
**Showing post:** 29

<div class="post-metadata">

### Author: ![JDW](https://discourse.softpress.com/user_avatar/discourse.softpress.com/jdw/32/2729_2.png) [@JDW](https://discourse.softpress.com/u/JDW)
#### Post date: [March 3, 2017, 4:21am UTC](https://discourse.softpress.com/t/pro-javascript-for-search-field-safari-problems/23703/29 "2017-03-03T04:21:06Z")

</div>

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):

```auto
//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):

```auto
//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:

> **[Information for existing FreewayTalk / Groups.io users](https://discourse.softpress.com/t/information-for-existing-freewaytalk-groups-io-users/24891)**
>
> The purpose of this topic is to provide information about the migration from FreewayTalk and Groups io to Discourse and the differences in Discourse, as well as a place to discuss the good or bad of the migration. For those previously subscribing...

---

_[View the full topic](https://discourse.softpress.com/t/pro-javascript-for-search-field-safari-problems/23703)._
