473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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?

Jul 23 '05 #1
3 4197
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" <b6*****@hotmail.com> wrote in message
news:mr********************@comcast.com...
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?

Jul 23 '05 #2
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.


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
Jul 23 '05 #3
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" <b6*****@hotmail.com> wrote in message
news:mr********************@comcast.com...
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?

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Janet | last post by:
The following html code appears in an ASP page. The hyperlink is set to white (see the page link color), but when the page renders in IE 6.0, it initially appears in maroon with a white border...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
7
by: G. Dean Blake | last post by:
I have a hyperlink on my aspx page added at dev time. Is there a way to execute it from code? Thanks, G
3
by: MrMike | last post by:
I have the following hyperlink webcontrol. The problem is that I can't figure out how to pass the webform's Request.Querystring("id") param into the NavigateURL as shown below. As it is currently...
0
by: stan | last post by:
I have a rather large html file where hyperlink specs are contained in a CSS file. When clicking or hovering there is about a 5 second delay before there is evidence of the link (when the hand...
4
by: Samuel Shulman | last post by:
I am trying to add HyperLink column with an image Below is the code that I use <asp:TemplateField> <ControlStyle Height="75px" Width="75px" /> <ItemStyle Height="75px" Width="75px" /> ...
20
by: tshad | last post by:
I had posted this problem earlier and just noticed that the Hyperlink is the problem. Apparently, it doesn't figure out the path correctly. It uses the path of the file it is in, even if it is...
5
by: Thirdworld | last post by:
I'm trying to create a hyperlink button on a form that does the following: 1. User clicks on button 2. The default 'insert hyperlink' window appears 3. User selects the desired file 4. User...
4
by: mark4asp | last post by:
I want to write a xslt template to create a xhtml 1.0 (transitional) file which will be sent in as email. Here is a typical xml data file: <BatchEmail> <Domain>www.myDomain.com</Domain>...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.