Connecting Tech Pros Worldwide Forums | Help | Site Map

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

The Dana's
Guest
 
Posts: n/a
#1: Jul 23 '05
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?






Carter Smith
Guest
 
Posts: n/a
#2: Jul 23 '05

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


That's impossible with HTML only. You have to use a scripting language such
as PHP to check if a file exists or not. And to use PHP the user must have
PHP installed and go through a web-server such as Apache to view the page
correctly.

This is something that would only be done server side. Not client side.

Ben Kucenski
www.icarusindie.com




"The Dana's" <b63dana@hotmail.com> wrote in message
news:mrKdnSxMuKcd7ZzfRVn-ow@comcast.com...[color=blue]
> 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[/color]
to[color=blue]
> 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?
>
>
>[/color]


Dietmar Meier
Guest
 
Posts: n/a
#3: Jul 23 '05

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


The Dana's wrote:
[color=blue]
> 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.[/color]

In browsers that implement XMLHttpRequests (current MSIE and Mozilla),
you can use it to validate links. An example document (here I only change
the background color, you can remove the link from the document instead)
is here: http://www.innoline-systemtechnik.de...alidlinks.html

Note: In older browsers, that do not implement try..catch, this script
will result in a syntax error. Browsers that do implement try..catch, but
not XMLHttpRequest, will state all links as unconfirmed.

ciao, dhgm
The Dana's
Guest
 
Posts: n/a
#4: Jul 23 '05

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


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>

"The Dana's" <b63dana@hotmail.com> wrote in message
news:mrKdnSxMuKcd7ZzfRVn-ow@comcast.com...[color=blue]
> 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[/color]
to[color=blue]
> 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?
>
>
>[/color]


Closed Thread