Iframe's src attribute

S

Santel

Hi,

The below code doesn't display the txt file in IFrame.

<iframe src=C:\Samples\Samples.txt></iframe>

Only when I place the txt file inside my application directory, it
works. Is this not possible to give cross-domain src in frames?
 
D

Dylan Parry

Santel said:
Only when I place the txt file inside my application directory, it
works. Is this not possible to give cross-domain src in frames?

Completely possible, but in your case you were referencing a file on
your local system via an absolute URL (ie. c:\), and due to security
settings in your browser you aren't able to do this. Otherwise any
website could load the contents of any file on your system into an
iframe, access it with Javascript and send the contents on to a
malicious website. This would be a bad thing!

--
Dylan Parry
http://electricfreedom.org | http://webpageworkshop.co.uk

Programming, n: A pastime similar to banging one's head
against a wall, but with fewer opportunities for reward.
 
S

Santel

Thanks for the reply Dylan.

Accessing it with javascript will be getting problem, Isn't it? The
file may be of any type like doc, htm etc; So any other options to do
this?
 
D

Dylan Parry

Santel wrote:

[Linking to file on local file system]
So any other options to do this?

You're always going to run into problems trying to link to files on your
local system (ie. via a c:\ URI), so the only way you can really do it
is to put the files you want to link to directly into your website's
root directory (ie. where you put your HTML pages), or if you are able
to, you can create a virtual directory that points to wherever your
files are.

--
Dylan Parry
http://electricfreedom.org | http://webpageworkshop.co.uk

Programming, n: A pastime similar to banging one's head
against a wall, but with fewer opportunities for reward.
 
S

Santel

Hi Dylan Parry,

This is my actual requirement. I should allow the user to select any
particular file from local disk (using open dialog) and display it in
IFrame. So in this case, I couldn't restrict the user to select the
file from a particular location. :(
 
D

Dylan Parry

Santel said:
This is my actual requirement. I should allow the user to select any
particular file from local disk (using open dialog) and display it in
IFrame.

Then using a webpage really isn't the best way of doing it. The security
settings in almost every browser won't let you do what you are
attempting. I would suggest that you either re-evaluate your needs, or
look into developing a proper application that does what you are trying
to achieve.

--
Dylan Parry
http://electricfreedom.org | http://webpageworkshop.co.uk

Programming, n: A pastime similar to banging one's head
against a wall, but with fewer opportunities for reward.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top