70974

Display message in iframe, if there is a .doc file which cannot be displayed

Question:

I am using iframe to display pdf or doc file on the page. pdf without any doubt displayed perfectly but doc file just downloaded and i am aware why.

Now the problem is I want to display a message in iframe that the file was a doc files so cannot be displayed and need to be downloaded to view.

till now I have searched and found various solutions to display a message or anything while loading iframe but I guess here its not the case of loading anything.

here is <a href="http://jsfiddle.net/hdbhandari/7803gakc/" rel="nofollow">fiddle</a>

Answer1:

Show some sample code so we can give you best solution. you can use js fiddle as well.

Otherwise you can add if condition to check the check file type and show the alert notification to users.

Answer2:

What about you check what file-type it is before you change or set the iframe?

If it is pdf, you display the file in the iframe, if it is doc, you load another html file with the message instead.

Also, as the other guy said, please show some examples of what you have done!

<strong>EDIT:</strong> Use javascript. Have a look at this code and tell me if it helps <a href="http://jsfiddle.net/7803gakc/1/" rel="nofollow">http://jsfiddle.net/7803gakc/1/</a>

// Not really sure about another way if it's going to be pure js/html and nothing server-side // Here's the location to the file var file = "http://www.ieee.org/documents/ieeecopyrightform.doc", // The frame being used frame = document.getElementById("frame"), // Files that will be allowed to be embedded based on extension extensions = ["pdf"], // This will tell us if it's right or not correct = false; // Loop through the extension list for(var i = 0; i < extensions.length; i++){ // Check if the file url ends with the given extension if(file.substring(file.lastIndexOf(".")+1) == extensions[i]){ // All conditions met, set to true! correct = true; } } if(correct){ // Yay, it's correct! frame.src = file; }else{ // It's wrong, show something else! frame.src = "http://example.com"; }

Answer3:

I couldn't find any solution to display message in iframe, may be it doesn't provide, so I switched to object tag.

<object data="[path to .doc]" type="application/msword">

It appears you do not have a Suitable plugin for this browser. You can download this file. <a href="[path to .doc]"> <button type="button">download</button></a>

Recommend

  • Trouble downloading file from browser on Android
  • Reload UITableView from another tab
  • PushKit for VOIP iOS apps
  • Why cepheus don't send int without quotes to orion?
  • C# program and C++ DLL compiled for 32-bit system crash on 64-bit system
  • std::remove_copy_if_ valgrind bytes in block are possibly lost in loss record
  • presentShareDialogWithParams posts to FB wall, but callback handler results say error
  • Loading .coffee files via a view in Rails
  • How to use JavaScript to determine whether a file exists in a directory?
  • Create DicomImage from scratch using Dcmtk
  • How to write order and limit within cakephp joins array
  • Functions in global context
  • FileReader+canvas image loading problem
  • req.body is undefined - nodejs
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Modifying destination and filename of gulp-svg-sprite
  • Sending data from AppleScript to FileMaker records
  • MySQL WHERE-condition in procedure ignored
  • Cassandra Data Model
  • Importing jscolor library in angular 2
  • Calling of Constructors in a Java
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Compare two NSDates in iPhone
  • Traverse Array and Display in markup
  • Transpose CSV data with awk (pivot transformation)
  • KeystoneJS: Relationships in Admin UI not updating
  • AngularJs get employee from factory
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • Load html files in TinyMce
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • How to set the response of a form post action to a iframe source?
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • Change div Background jquery
  • Android Google Maps API OnLocationChanged only called once
  • Qt: Run a script BEFORE make
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • reshape alternating columns in less time and using less memory
  • UserPrincipal.Current returns apppool on IIS
  • How to load view controller without button in storyboard?