Jump to content

How to identify the page type on the current page


optikalefx

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>

Link to comment
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

Link to comment
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

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.