Jump to content

Archived

This topic is now archived and is closed to further replies.

optikalefx

How to identify the page type on the current page

Recommended Posts

 

alright, try this - I think I just rehashed something I already did; but try it anyway - lol :D

 

<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>

Share this post


Link to post
Share on other sites

 

here is another version; I tricked this one out - pimped my script - lol :D

 


<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 :D

Share this post


Link to post
Share on other sites

MAD PROPS MAN!!!

 

great job!

 

it works!

 

Ill recommend you to my comrads.  Thanks so much!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

 

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

 

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.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.