/    Sign up×
Community /Pin to ProfileBookmark

Is it possible to link to a virtual file? This question is best explained by example:

When executing a hyperlink, a browser uses the link extension to determine how to handle the link. For example, if the extension is “.html”, the browser simply opens a new browser window. For links with a “.xls” extension, the browser displays a dialog box prompting the user for the required program to open the link (Microsoft Access in this case). These examples refer to physical files located on the user’s hard drive or Internet server. But what if the file is virtual, existing only in a javascript variable? For instance, if the following code is saved in a local file named “home.kml” and referenced in an anchor tag (<a href=”home.kml”>) the browser will attempt to open Google Maps to process the file.

[CODE]
<?xml version=”1.0″ encoding=”UTF-8″?>
<kml xmlns=”http://earth.google.com/kml/2.0″>
<Placemark>
<name>My House</name>
<LookAt>
<longitude>-112.1604897451107</longitude>
<latitude>33.5435585988906</latitude>
<range>122.7990952690303</range>
<tilt>-1.543474315911411e-010</tilt>
<heading>-0.04806666315645621</heading>
</LookAt>
<visibility>0</visibility>
<styleUrl>root://styles#default+icon=0x307</styleUrl>
<Point>
<coordinates>-112.1604897451107,33.5435585988906,0</coordinates>
</Point>
</Placemark>
</kml>
[/CODE]

I can compose a javascript routine that will create the text of the code on the fly and place it in a variable named “MyHouse”. My question is how do I get the browser to execute the code as if were a file with a “.kml” extension?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@crh3675Jul 05.2005 — You have to pass a content-type header with the file. Browsers do not process file extensions. Browsers process a file by the content-type header. You would need to prepend the content-type from the server side to do what you want.
Copy linkTweet thisAlerts:
@ShadoefaxauthorJul 05.2005 — Craig, That is not necessarily true. I just tried an experiment. I have two identical files named “doc.txt” and “doc.doc” on my local drive. When I link to “doc.txt” the browser simply dumps the content to my screen. Linking to “doc.doc” opens the dialog box prompting me to use Microsoft Word to open the file. Like I said, the two files are identical with no header information (at least none that I put in) enclosed.

So apparently, the browser must use the extension to determine file type.
Copy linkTweet thisAlerts:
@crh3675Jul 05.2005 — That's IE doing that, trying to recognize the file by extension. Unless you have the extension setup in your computer (File Types) to be recognized by a certain program, this will not always work as anticipated.
Copy linkTweet thisAlerts:
@ShadoefaxauthorJul 05.2005 — Craig, Actually I am using FF (not IE) but you are correct.

But this does not really help much in regard to my original question/problem. Do you have any suggestions as to how I can link to code contained in a variable as if it were a file with a particular extension?
×

Success!

Help @Shadoefax spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...