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 iterate over the array, however, using a loop alone will not completely fix the problem, because you're assigning a function inside the loop, which means any outside variables could change before the `onclick` executes.

So what you need is a closure.

1. Create a function that sets the `onclick` callback
2. Call that function in a loop.

Here's an example:

```
function setOnClick(element, imgSrc) {
  element.onclick = function() { img.src = imgSrc; };
}

for (var i = 0; i < thumb.length; i++) {
  setOnClick(thumb[i], pArray[i]);
}

```

This functionality is very common, so it has also been implemented by [`Array#forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach):

```
pArray.forEach(function(imgSrc, index) {
  thumb[index].onclick = function() { img.src = imgSrc; };
});

```