Question: I want to show Interstitial ad on a webview app and make the ad opens immediately after openning a page (article) as admob policies said to me to make the ad appear in normal transition points.

Can you show me how to do that?

And I want also to know how to control the ad appearance as I don't want the ad to show every time the user opens a link?

Answer: 
Assuming that you'll have the same amount of elements in `pArray` as you would have thumbnails, you would do this:

```
Array.prototype.forEach.call(thumb, function(thumbItem, index) {
  thumbItem.onclick = function() {
    img.src = pArray[index];
  };
});

```

It iterates through the thumbnails, attaching the `onclick` handler and assigning the main image with the corresponding image based on the element's index.
You could use the `loop` for any array, we usually use the `for loop` for related arrays.

```
for (var i = 0; i < thumb.length; i++) {
    thumb[i].src = pArray[i]; // change if different src
    thumb[i].onclick = function() { img.src = this.src; };
}

```

Try on: <https://jsfiddle.net/Zay_DEV/8r1gqnfx/>

```js
var img = document.getElementById("galleryImg");
var thumb = document.getElementsByClassName("imgThumb");
var pArray = [
 "https://dl.dropboxusercontent.com/u/89495286/test/images/pic1.png",
  "https://dl.dropboxusercontent.com/u/89495286/test/images/pic2.png",
  "https://dl.dropboxusercontent.com/u/89495286/test/images/pic3.png",
  "https://dl.dropboxusercontent.com/u/89495286/test/images/pic4.png",
  "https://dl.dropboxusercontent.com/u/89495286/test/images/pic5.png",
  "https://dl.dropboxusercontent.com/u/89495286/test/images/pic6.png"
]

for (var i = 0; i < thumb.length; i++) {
 thumb[i].src = pArray[i];
 thumb[i].onclick = function() { img.src = this.src; };
}

thumb[0].onclick();
```

```css
#galleryImg { max-height: 25vh; }
.imgThumb { width: 100px; height: 50px; }
```

```html
<img id="galleryImg"/>
<br />

<img class="imgThumb"/>
<img class="imgThumb"/>
<img class="imgThumb"/>
<img class="imgThumb"/>
<img class="imgThumb"/>
<img class="imgThumb"/>
```