manipulate another web page via javascript

Asked

Viewed 1,227 times

1

The following is, I need to access a website and do a search on it through my page. I am trying as follows:

<html> <script type="text/javascript" src="js/jquery.js"> </script>

<div class="news">  <iframe src="http://alelo.com.br/consulta-saldo-extrato-alelo.html" style="width:100%; height:100%; float:left;" frameborder="0" id = "jones"></iframe> </div>

<input type = "text" id = "piru">

<script> document.getElementById('jones').onload= function() {      var valor = $('#jones').contents().find('#numero').val();  alert(valor);    }

</script> </html> 

I’m not getting anything done on the page inside the iframe... Help!

  • If the site is not within the same domain as yours then you will not be able to access the site.

  • Use Curl. http://php.net/manual/en/book.curl.php http://curl.haxx.se/

  • I’m gonna take a look at these sites that you gave me, thank you.

1 answer

1

If the site is not within the same domain as yours then you will not be able to access the site. This has to do with security rules (CORS) to prevent the manipulation of a page with Javascript via iframe.

The mistake it gives you is possibly this (from this example):

Uncaught Securityerror: Failed to read the 'contentDocument' Property from 'Htmliframeelement': Blocked a frame with origin "http://fiddle.jshell.net" from accessing a frame with origin "http://alelo.com.br". Protocols, Omains, and ports must match.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.