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 8 of 8
  1. #1
    New Coder
    Join Date
    Mar 2013
    Posts
    55
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Question How can I grab the contents from a PHP file that is opened in my browser?

    One my main webpage(MyPage.htm), I have different JavaScript functions, to grab different parts of another page(OtherPage.htm), that I have within an iFrame on my main page.

    I grab the URL with...

    Code:
    document.all.myFrame.contentWindow.location
    and I can grab the text within a textbox with...

    Code:
    document.all.myFrame.contentWindow.myform.message.value
    I have a PHP file(File.php) and I would like to grab the contents on that but I don't know how to. It's a very short file, only about 15 to 20 characters long. The is no HTML tags, it just says "MrAtoBandMe12345678910".

    How can I grab the info from it by using the same types of code from above? My goal is to do it in a JavaScript function, just like the other functions. I'm not wanting to open the file and copy the text, just copy the HTML/info from the iFrame.

    I've tried these things, but none worked...

    document.all.myFrame.contentWindow.innerhtml.value

    document.all.myFrame.contentWindow.inner.html.value

    document.all.myFrame.content.Window.innerhtml.value

    document.all.myFrame.content.Window.inner.html.value

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    document.all? Are you still supporting IE4?

    Use document.getElementById.

    Code:
    alert(document.getElementById('myFrame').contentWindow.document.documentElement.innerHTML)
    You may also use outerHTML if you want. This is also non-standard like innerHTML which Microsoft invented but other browsers were "forced" to implement.

    http://stackoverflow.com/questions/8...html-as-string

  • Users who have thanked glenngv for this post:

    MrAtoBandMe (04-27-2013)

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,133
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    If Glenn wasn't clear: document.all *ONLY* works in MSIE. And, as he notes, became obsolete when IE5 came along, in March of 1999.

    If you see code using document.all, it's a clear sign that it is too obsolete to ever bother with. Run away from it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    MrAtoBandMe (04-27-2013)

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,133
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    But I am also wondering: *DO* you have that File.php loaded into an <iframe>? Or not?

    If not, you could use AJAX to grab it, then no need to have it in an <iframe>.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    Mar 2013
    Posts
    55
    Thanks
    27
    Thanked 0 Times in 0 Posts
    That work! Thanks.

    Now, I would like to do the same thing, but I would like to do it with the Google Chrome browser, and with the "--disable-web-security" applied.

    The problem I am having, it that the page shows up with an encoding error(it appears to be Chinese and it also has the squares in it). Any idea how to fix this?

    When I go to 'view source', the HTML looks completely normal. This same page works in Chrome with web security disable, but not in an iFrame. The same page works in and out of an iFrame with the Internet Explorer browser. It also works fine within an iFrame in Chrome, but only in the 'safe' browser. So, it is specifically, in Google Chrome, in an iFrame, and with "--disable-web-security", that causes it.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,133
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    But I hope you understand that when you use --disable-web-security *ONLY* you, looking at YOUR screen, can see the results. Your page WILL NOT WORK for anyone else unless they also run Chrome with security disabled. Maybe 1 person in a million will do that.

    If you want others to be able to see cross-site content, you almost surely need to create a PHP proxy server, so that the content *appears* to all be coming from your own site.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    New Coder
    Join Date
    Mar 2013
    Posts
    55
    Thanks
    27
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    But I hope you understand that when you use --disable-web-security *ONLY* you, looking at YOUR screen, can see the results. Your page WILL NOT WORK for anyone else unless they also run Chrome with security disabled. Maybe 1 person in a million will do that.

    If you want others to be able to see cross-site content, you almost surely need to create a PHP proxy server, so that the content *appears* to all be coming from your own site.
    I know. I'm just doing it for the learning.

    It was working fine, and now I get this encoding problem, but only on some pages. Could it be something like Flash or Active X?

  • #8
    New Coder
    Join Date
    Mar 2013
    Posts
    55
    Thanks
    27
    Thanked 0 Times in 0 Posts
    derp, just figured it out...I just needed to set it to Auto-Detect. lol


  •  

    Posting Permissions

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