Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Image to appear while typing: coding question

Featured Replies

Hi all, 

I'm attempting to create something for my work to help support young people and adults with communication needs. Part of the website aims to include an area where when you type the name of an image (or something related) that image would appear above it. For example, if you typed 'chocolate' into the text bar, it would link back to an image of chocolate and that would display above automatically. 

Is this possible or am I reaching to far? If possible what type of coding would it require 

 

Thanks in advance! 

Jon

Really depends. 

Where are these images? Do you have a number of images stored somewhere, that you would like to retrieve when the user types into the textbox? Or are you aiming for something more like a Google image search, wherein the user can type any search term and be shown an image? 

If you're aiming for the first scenario with stored images, I'd recommend: 

Use the following JS-library to preload a JSON manifest of images, assign them tags e.g. "Chocolate", "Flowers" etc. 
https://www.createjs.com/preloadjs

Create a textbox with an onchange value that calls a JavaScript function. Have this JS function write matching image/s to the screen. Effectively, this solution would be handled solely on the client-side, so, should be pretty snappy. 

<div id="image_shows_here"></div>
<input id="txt_search" type="text" onchange="getImages()">

<script>
 
function getImages(){

  //Write your images to the page here...
  
}
  
</script>

If you're looking for functionality that is similar to a search engine image search, you'll have to lean on an API to achieve this. As far as I know, Google Images API is discontinued. Bing does offer a service as linked below: 

https://azure.microsoft.com/en-us/services/cognitive-services/bing-image-search-api/

You'd need to look at making AJAX requests (most likely) to the API if you wanted the images to appear without page refresh. You'd also have to place a great deal of faith in the "Safe Search" capabilities of Bing - you'd be serving images on your website/app from arbitrary sources. For example, what's to stop me searching for "boobies" and populating your website full of NSFW content. Again, you're leaning on a pretty well-established search engine, so this should, in theory, be safe, but some images are bound to slip the net which is something to consider. 

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.