0

I have an HTML page which loads some content in an iframe with the help of remote JS. I want to replace the text "premium content" with something else.

What I am trying is:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript" src="http://gaand.comli.com/no.js"></script>

<img src="psss" onerror="myFunction()"></img>
<script>
function myFunction() {
    var x = document.getElementById("overlay_iframe");
    var y = x.contentDocument;
    y.document.body.innerHTML = y.document.body.innerHTML.replace('premium', 

'newtext'); 
}
</script>
</body>
</html>

Is there any way to change it as soon as the page is loaded completely?

0

4 Answers 4

1

You can use jquery to have event when page loads, and then replace html content.

$( document ).ready(function() {
   $( "#overlay_iframe" ).html( $( "#overlay_iframe" ).html().replace("premium","newtext"));
});
Sign up to request clarification or add additional context in comments.

1 Comment

Still not working. I can change text on a page easily. But in this case with iframe not working
0

Unless the iFrame is on your server you cannot change it. I would suggest using PHP

file_get_contents()

and replacing it within the string.

Comments

0

You can try using the jQuery .contents() to return an object of the iframes contents and than manipulate that. jQuery .contents()

Comments

0

Edit, updated

Try

$.getScript("http://gaand.comli.com/no.js")
.done(function(script) {
    s = setInterval(function() {
      $("iframe").contents()
      .find("body").text(function(_, o) {
         return o.replace("premium", "newText");
      }) && clearInterval(s);
    }, 10);
});

jsfiddle http://jsfiddle.net/guest271314/whjqqtco/

7 Comments

it returns me a blank page without any frame
Tried without $.getScript() ? With script tag , as at OP ? Then setInterval piece in next script block ?
yes tried just now. Again I can see "Premium Content Area". Its no replaced by newText
If possible , can post iframe html ? Is piece inside of img's error function ? , or in separate script tag / block ?
img tag I just used to call the myfunction(). actually what I am trying to do is. when I use <script src="gaand.comli.com/no.js"></script> in an html. This no.js loads an iframe and I need to change the text in it using js. I dont have source for the iframe as its loaded with this JS.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.