dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: Get iframe Url of failed page

  1. #1
    Join Date
    Sep 2013
    Posts
    3

    Get iframe Url of failed page

    I would like to get the url of the iframe when the page fails to load. Everytime I try I keep getting the original url of the iframe not the url it tried to access but failed on. How would I achieve this ?
    Here is my current script:

    var url1 = document.getElementById("ifrim").src;

    alert(url1.toString());

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,941
    Only thing I can suggest :
    Code:
    iframe = document.getElementById("theIframe");
    iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
    url = iframeDoc.location || iframeDoc.URL;
    url will equal the URL of the iframe
    STOP using $ prefix on JavaScript variable names...
    Please remember to wrap any code you have in forum tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,941
    Also... if you get an error 404 page, you can test for a failed page load by
    Code:
    loadedOK = iframeDoc.body.innerHTML.indexOf("Error 404")>-1?false:true;
    where loadedOK is true, you have a loaded page otherwise false is a failed load.
    STOP using $ prefix on JavaScript variable names...
    Please remember to wrap any code you have in forum tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles