Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7585841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:16:26+00:00 2026-05-30T19:16:26+00:00

I have a iframe in my page. If the iframe doesn’t load, want it

  • 0

I have a iframe in my page. If the iframe doesn’t load, want it to alert the message “pdf not found” and if the iframe does load, it should alert “pdf opened“.

Does anyone know how to achieve that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:16:28+00:00Added an answer on May 30, 2026 at 7:16 pm

    So, the idea is to use an Ajax-request to “test” the URL. Ajax-requests enable you to bind “success” and “error” handlers – unlike <iframe> elements which only provide a “load” handler.

    Of course, Ajax-requests are restricted by the Same Origin Policy (unless the web-server enables CORS), but you stated that the PDF is on the same domain, so there shouldn’t be any issues.

    Also, you stated that you use the Mootools library – I use jQuery, so I can only provide you with a jQuery solution, but since we’re making a simple Ajax-request with “success” and “error” handlers, you should be able to recreate a Mootools solution based on my jQuery solution easily.

    So, given an iframe and an URL:

    var iframe = $( '#iframe' )[0]; // reference to IFRAME element
    var url = 'files/document1.pdf';
    

    The Ajax-request:

    $.get( url, function () {
        iframe.onload = function () { alert( 'PDF opened!' ); };
        iframe.src = url;
    }).error( function () { alert( 'PDF not found' ); });
    

    Success-demo: http://jsfiddle.net/CZWdL/1/show/
    Error-demo: http://jsfiddle.net/CZWdL/2/show/

    So, if the Ajax-request triggers an “error” event, we simply alert the “Not found” message immediately. If, however, the Ajax-request triggers a “success” event, we assign a “load” handler to our IFRAME element (this “load” handler will eventually alert the “Loaded” message), and set the URL to its src property manually.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webpage with one iframe and a button. On Page Load event,
I have a script that write a iframe into the page. I want to
I have an IFrame on my page pointing to a page containing list of
I have a iframe on my page. I have inserted a background image on
Basically, I have an iframe embedded in a page and the iframe has some
I have a div and an iframe on the page the div has z-index:
I have an HTML page (say welcome.html) which contains an iframe to a page
I have a page that has an iframe From one of the pages within
I have a page with an iframe. In the iframe is a form targeting
I have a page which has an Iframe. In that Iframe, there are six

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.