Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Manipulating page code viewed through an iframe.

    Hello,
    Iím developing a website ( http://www.phoebe2.com/ ) and employ the use of an iframe tag.

    Code:
    <iframe src="example.com/1.htm"></iframe>
    The page I open using the iframe is not controlled by me, but is displayed on my page.

    Is there a way I can intercept the source code of the frame and modify it before it is being displayed to the user?

    For example, retrieving the code, then substituting the word "dang" for the word "damn".

    So when the finial user sees it, they will see:

    "Frankly my dear, I donít give a dang."

    Instead of:

    "Frankly my dear, I donít give a damn."

    Thanks for any help.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Edinburgh, UK
    Posts
    402
    Thanks
    2
    Thanked 1 Time in 1 Post
    I can't actually do the code for you at the moment, but something that you may want to think about is firstly naming the iframe something. Then once the page has been loaded, the JS could get the innerHTML, assign this to a variable, search through the source for your ''bad words'', swap them for your good words, and then set the iframe's innerHTML for the new one.

    Hope this helps.
    Rich

    "An expert is a person who has made all the mistakes that can be made in a very narrow field."

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    If the page in the iframe is in a different domain, then you don't have access to that page. Be thankful there is such kind of security measure. Had it been possible, imagine what would happen to the Web if someone can just frame anybody's page and changes its contents like, for example, the opposite of what you want.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmmm, Iím getting a conflicting answer.

    Iím going to make myself believe it can be done, because I would like to see it done.

    It would also seem possible, since lots of sites on the web GRAB html data from documents, ie all those HTML valuator sites. It would seem possible that if you GRAB your html from the source, then do a replace like below, then output that data.

    Code:
    html = html.replace (/damn/g,"darn");
    So, with that in mind, Iím going to pursue Badmanís advice.

    This is the code Iíve started to write, but itís not working.

    Code:
    <html>
    <head>
    <script>
    var html = document.test.innerHTML;
    html = html.replace (/damn/g,"darn");
    </script>
    </head>
    
    <body>
    <iframe src="http://www.a.com/" name="test" width="400" height="350"></iframe>
    </body>
    </html>

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's just like glenngv said - you don't have access to the DOM of a page outside your script's security scope (in a different domain)

    However there are exploits around that restriction in some browsers, so to avoid the possibility of anyone posting any of them, I'm closing this thread.
    Last edited by brothercake; 01-10-2005 at 08:36 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •