Skip to content Skip to sidebar Skip to footer

Display Message In Iframe, If There Is A .doc File Which Cannot Be Displayed

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 di

Solution 1:

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.

Solution 2:

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!

EDIT: Use javascript. Have a look at this code and tell me if it helps http://jsfiddle.net/7803gakc/1/

// 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 filevar 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 listfor(var i = 0; i < extensions.length; i++){
    // Check if the file url ends with the given extensionif(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";
}

Solution 3:

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">
<p>It appears you do not have a Suitable plugin for this browser. You can download this file.
    <ahref="[path to .doc]"><buttontype="button">download</button></a></p>

Post a Comment for "Display Message In Iframe, If There Is A .doc File Which Cannot Be Displayed"