SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Berlin
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I Display JavaScript source file in Explorer?

    I wrote some JavaScript I misguidedly thought cool, and felt like sharing it with the world. So I put a link to the source file in my blog. If I click on the link in Mozilla, it shows the source as text, as intended. If I click on it in Internet Explorer, I get a choice between saving the file or opening it, where 'opening it' means 'trying to run it and getting an error.' Putting
    Code:
    type="text/plain"
    in the a tag doesn't help. Does anything?
    Last edited by JamesCrompton; Jan 7, 2005 at 08:54. Reason: blog moved

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about saving your source file as .txt instead of .js or .htm?

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Berlin
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm. That works. But do any browsers object to having a JavaScript file delivered with a .txt suffix?

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Berlin
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just in case anyone's interested: in the end I did this:

    1. redirect the links for IE:
    Code:
    elements = document.getElementsByTagName( "a" ) ;
    for ( i=0 ; elements[i] ; i++ )
    	{
    	var theSuffix = elements[i].href.split( "." ).reverse()[0]
    	if ( ( theSuffix == "js" || theSuffix == "css" ) && 
    		elements[i].href.search( "showsource.html" ) == -1 )
    		elements[i].href = addDomain +
    		"/code/showsource.html?" + elements[i].href ;
    	}
    2. if you have Explorer or Mozilla/Firefox/maybe others too, showsource.html will show you its own source.
    Last edited by JamesCrompton; Feb 18, 2005 at 05:22. Reason: Moved showsource.html

  5. #5
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by JamesCrompton
    Hmm. That works. But do any browsers object to having a JavaScript file delivered with a .txt suffix?
    It would be treated as text if you give it a .txt extension, so it would never execute.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •