phpQuestioner Posted January 30, 2008 Share Posted January 30, 2008 alright, try this - I think I just rehashed something I already did; but try it anyway - lol <script language="javascript"> var presently = document.URL; var thisFile = presently.split("/"); var thisExt = presently.split("."); var total = thisFile.length - 1; var totaled = thisExt.length - 1; var getEXT = thisExt[totaled]; function getFileNameAndExt() { if (total > "3") { document.getElementById('viewIt').innerHTML = thisFile[total] + '<br/><br/>'; } else if (getEXT != "htm" || getEXT != "html" || getEXT != "php" || getEXT != "pl") // add more file types as needed { document.getElementById('viewIt').innerHTML='index.htm<br><br>'; } else { document.getElementById('viewIt').innerHTML='index.htm<br><br>'; } } </script> <div id="viewIt"></div> <a href="javascript:void(0)" onclick="getFileNameAndExt()">Where Am I At? - Click Here To Find Out</a> Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 30, 2008 Share Posted January 30, 2008 how did it work? Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 30, 2008 Share Posted January 30, 2008 here is another version; I tricked this one out - pimped my script - lol <script language="javascript"> var presently = document.URL; var thisFile = presently.split("/"); var thisExt = presently.split("."); var total = thisFile.length - 1; var totaled = thisExt.length - 1; var getEXT = thisExt[totaled]; function getFileNameAndExt() { if (getEXT == "htm" || getEXT == "html" || getEXT == "php" || getEXT == "pl") // add more file types as needed { document.getElementById('viewIt').innerHTML = thisFile[total] + '<br/><br/>'; } else { document.getElementById('viewIt').innerHTML='index.htm<br><br>'; } } </script> <div id="viewIt"></div> <a href="javascript:void(0)" onclick="getFileNameAndExt()">Where Am I At? - Click Here To Find Out</a> man I must be bored - lol Quote Link to comment Share on other sites More sharing options...
optikalefx Posted January 30, 2008 Author Share Posted January 30, 2008 MAD PROPS MAN!!! great job! it works! Ill recommend you to my comrads. Thanks so much! Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 30, 2008 Share Posted January 30, 2008 Awesome - I'm glad I got it working for you Quote Link to comment Share on other sites More sharing options...
optikalefx Posted January 30, 2008 Author Share Posted January 30, 2008 Ok, so i was wrong. If there is no file with extension in the URL IE www.mysite.com/ then it just says index.htm. Which is fine most of the time, except when the default page is index.php. Is there a way to detect that as well? The problem is that a server can default to index.htm OR index.php OR main.htm OR main.html OR index.html. How can i know which one of these its going Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 30, 2008 Share Posted January 30, 2008 Not unless you manually change the page extension from "htm" to "php" in the script I wrote for you. If there is no page extension in the URL; then the client side javascript has no idea what the page extension is. I think what I have provided you; is as close as your going to come to identifying the file name and page extension client side. Quote Link to comment Share on other sites More sharing options...
optikalefx Posted January 31, 2008 Author Share Posted January 31, 2008 well with what we are doing in our project, Im able to get into the FTP server of the client. But even having the file list of / directory of the site, i dont know how to tell which file is the main file. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 31, 2008 Share Posted January 31, 2008 I really don't know what to tell you. If the URL does not contain a filename or a file extension/type; the document.URL will not be able to detect what the file is; nor will any other dom event that I know of off hand. You will just have to determine where you want your domain to be directed to and set that file name and file extension in you else if and else condition. Beyond that; I think you would have to try a server side script; even then I am not sure it could do what you are wanting it to do; without the filename and file extension. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.