How to create hyperlink that appears only if the target file is present?

T

The Dana's

I need to create a static HTML file that runs only on the local client PC.

On the page (say PageA.htm), I would like for a hypelink to another page
(Page B) to appear ONLY if the target file the hyperlink references is
present (PageB.htm).

So If I'm viewing page A, and Page B is present, then I want a hyperlink to
show up on Page A to navigate to Page B.

If Page B is not present, then no hypelink would appear for Page B.

Can someone post some code that does this?
 
D

Disco Octopus

The Dana's wrote :
I need to create a static HTML file that runs only on the local client PC.

On the page (say PageA.htm), I would like for a hypelink to another page
(Page B) to appear ONLY if the target file the hyperlink references is
present (PageB.htm).

So If I'm viewing page A, and Page B is present, then I want a hyperlink to
show up on Page A to navigate to Page B.

If Page B is not present, then no hypelink would appear for Page B.

Can someone post some code that does this?

I just want to confirm...

- PageA.html is on the server?
- PageB.html may or may not be on the client PC (eg. c:\PageB.html)?
- In PageS.html, you want something that looks like this.....
if (There is a file on the filesystem called "c:\PageB.html")
Show the link the that file on this page.
else
Hide the link the that file on this page.
endif


Is this what you want? If so, then my first glance would be 'no'. it
can not be done.
there may be something in Java or Active that can interogate the
filesystem for file existance, but then your page will be dependant on
the user explicitely giving your 'plugin' permission to do so.
 
T

The Dana's

Both pages are on the client. No server here.

I playing around with a zero width frame to try this and have it working
somewhat with two A files, but need to get it down to a single File A
(always on client) and a referenced 'conditional' file B.
 
T

The Dana's

Thanks for all the help !

This worked:

---------------
Parent.htm
---------------

<html>
<head>
<title id="ParentChild">ParentChild</title>
</head>
<body><font face='Arial'>
<h1>This is the Parent</h1>
<ul>
<li><a href="child.htm">Go to Child</a></li>
</ul>
</html>

---------------
Child.htm
---------------

<html>
<head>
<title >Child</title>
</head>
<body><font face='Arial'>
<br><br><p><center>
<script language="javascript">
function masterWindow()
{
window.open("parent.htm", "_top");
}

var oDummy = new Image();
oDummy.src = "parent.htm";
var sURI = oDummy.src.replace(/[#?].*$/, "");

try {
var oHttpReq = window.ActiveXObject
? new ActiveXObject('Microsoft.XMLHTTP')
: window.XMLHttpRequest
? new XMLHttpRequest()
: null;
if (oHttpReq) {
oHttpReq.open('HEAD', sURI, false);
oHttpReq.send(null);

var iStat = oHttpReq.status;
if (iStat >= 400) {
var bShow = false;
} else {
var bShow = true;
}
}
}
catch(e) {
var bShow = false;
}

if (bShow) {
document.write("<form>");
document.write(" <input type='button' value='Go to Parent'
onClick='masterWindow()' />");
document.write("</form>");
}

</script>
</html>
 
D

Dan

The said:
This worked:

For some definitions of "worked", at least.
Parent.htm

Or "parent.html" if you'd rather use the traditional file extension for
HTML rather than the dumbed-down 3-letter Microsoftism.
<body><font face='Arial'>
<h1>This is the Parent</h1>

It's invalid to nest <h1> (or any other block-level element) within a
font element. You also fail to close the font element anywhere in your
var oHttpReq = window.ActiveXObject
? new ActiveXObject('Microsoft.XMLHTTP')

That doesn't look very platform-neutral. How many different browsers
and platforms have you tested it in?
 
D

Dylan Parry

Dan said:
That doesn't look very platform-neutral. How many different browsers
and platforms have you tested it in?

The OP has said that it is a page that won't be on a server, i.e. it is
on his machine only. So I don't think that cross-platform W3C-validating
code is very important in this scenario.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top