# 能否将搜索表单放在我们404页面的顶部？

**URL:** <https://meta.discourse.org/t/can-i-put-the-search-form-at-the-top-of-our-404-page/210406>\
**Category:** Product Support\
**Created:** [2021 年11 月 29 日 14:30 UTC](https://meta.discourse.org/t/can-i-put-the-search-form-at-the-top-of-our-404-page/210406 "2021-11-29T14:30:45Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

作者： ![rmccown](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rmccown/32/155375_2.png) [@rmccown](https://meta.discourse.org/u/rmccown)\
发布日期： [2021 年12 月 2 日 14:50 UTC](https://meta.discourse.org/t/can-i-put-the-search-form-at-the-top-of-our-404-page/210406/9 "2021-12-02T14:50:57Z")

</div>

回复我自己。我将 .innerHTML 调用包装在 try/catch 块中

```plaintext
<script type="text/javascript">
    var x = document.getElementsByClassName("page-not-found"); 
    var search = '<div class="page-not-found-search-top"><h2>Search this site</h2><p></p><form action="/search" id="discourse-search"><input type="text" name="q" value=""><button class="btn btn-primary">Search</button></form><p></p></div>'
    try {
        x.item(0).innerHTML += search
    } catch (error) {
    }
</script>

```

---

_[View the full topic](https://meta.discourse.org/t/can-i-put-the-search-form-at-the-top-of-our-404-page/210406)._
