Jump to content
Fórum Script Brasil
  • 0

[RESOLVIDO] Script não funciona no Chrome


Fábio Penna

Question

Olá Pessoal, sou leigo em java, e estou com um problema.

Estou executando o script abaixo, e no IE funciona perfeitamente, mas no Chrome não funciona, alguém pode me ajudar?

Esse código está sendo executado no http://www.fabiopennafotografo.com.br.

<script type="text/javascript">

var imageCount = 0;

var currentImage = 0;

var images = new Array();

images[0]= 'fundo2';

images[1] = 'fundo3';

images[2] = 'fundo4';

images[3] = 'fundo5';

images[4] = 'fundo6';

images[5] = 'fundo7';

images[6] = 'fundo1';

for (var i = 0; i < images.length; i++)

{

imageCount++;

}

function startSlideShow()

{

document.getElementById( ''+images[currentImage]+'' ).click();

currentImage = currentImage + 1;

if (currentImage > (imageCount-1))

{

currentImage = 0;

}

}

setInterval('startSlideShow()', 15000);

</script>

<ul class="pagination">

<li class="current"><a href="images/bg_img1.jpg" id="fundo1" name="fundo1">1</a></li>

<li><a href="images/bg_img2.jpg" id="fundo2" name="fundo2">2</a></li>

<li><a href="images/bg_img3.jpg" id="fundo3" name="fundo3">3</a></li>

<li><a href="images/bg_img4.jpg" id="fundo4" name="fundo4">4</a></li>

<li><a href="images/bg_img5.jpg" id="fundo5" name="fundo5">5</a></li>

<li><a href="images/bg_img6.jpg" id="fundo6" name="fundo6">6</a></li>

<li><a href="images/bg_img7.jpg" id="fundo7" name="fundo7">7</a></li>

</ul>

Edited by Fábio Penna
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Pessoal, depois de pesquisar bastante, consegui a solução, tem que registrar o evento antes de executar:

<script type="text/javascript">

var imageCount = 0;

var currentImage = 0;

var images = new Array();

images[0]= 'fundo2';

images[1] = 'fundo3';

images[2] = 'fundo4';

images[3] = 'fundo5';

images[4] = 'fundo6';

images[5] = 'fundo7';

images[6] = 'fundo1';

for (var i = 0; i < images.length; i++)

{

imageCount++;

}

function startSlideShow()

{

// SE o navegador não conheça o evento, registra:

if(typeof HTMLElement!='undefined'&&!HTMLElement.prototype.click)

HTMLElement.prototype.click=function(){

var evt = document.getElementById(''+images[currentImage]+'').ownerDocument.createEvent('MouseEvents');

evt.initMouseEvent('click', true, true, document.getElementById(''+images[currentImage]+'').ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);

document.getElementById(''+images[currentImage]+'').dispatchEvent(evt);

}

document.getElementById( ''+images[currentImage]+'' ).click();

currentImage = currentImage + 1;

if (currentImage > (imageCount-1))

{

currentImage = 0;

}

}

setInterval('startSlideShow()', 15000);

</script>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...