/    Sign up×
Community /Pin to ProfileBookmark

unclickable hyperlink

I have a web page with 2 frames, it has a navigation bar in a frame, and whatever u click on in that frame will appear in the second frame. how do i get the hyperlink to become unclickable when that hyperlink is open in the second frame?

to post a comment
JavaScript

17 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliJul 29.2003 — Here is what you can do,

in the onclick event of the anchor tag call a javascript function

in that function target the iframe/other frame and see whats the document being displayed in it,if it matches the target of the link then return false else return true
Copy linkTweet thisAlerts:
@SlankenOgenJul 29.2003 — function checkLinks(thisLink){

var lgn = document.links.length;

var k = 0;

for(k = 0; k < lgn; k++){

if(thisLink == document.links[k]){

return false;

}

}

document.location.href = thisLink;

return false;

}

}

}


<a href = "#" onclick = "return parent.frames[1].checkLinks('www.blah.com')">###</a>
Copy linkTweet thisAlerts:
@rushie84authorJul 29.2003 — I appreciate the replies. SlankenOgen, I tried the code you gave me, but didn't have any success with it. Make sure this is correct:

function checkLinks(thisLink){

var lgn = document.links.length;

var k = 0;

for(k = 0; k < lgn; k++){

if (thisLink == document.links[k]){

return false;

}

}

document.location.href = thisLink;

return false;

}

And then this is what I have around the links themselves:

<a href=welcome.html target="welcomeframe" onClick="return parent.frames[1].checkLinks('welcome.html')">Welcome</a>

I'm at a loss. Can u help me?
Copy linkTweet thisAlerts:
@SlankenOgenJul 29.2003 — Ok, put this in 'welcomeframe' -

function checkLinks(thisLink)

{

var lgn = document.links.length;

var k = 0;

for(k = 0; k < lgn; k++)

{

alert(document.links[k]);

if(thisLink == document.links[k])

{

alert(thisLink+" is on this page also.");

return false;

}

}

document.location.href = thisLink;

return;

}

and you must nullify the links on the links frame with a hash (#) like this-

<a href = "#" onclick = "return parent.frames['welcomeframe'].checkLinks('file:///C:/Documents%20and%20Settings/Owner/Desktop/mgb/JavaScript/menu2.html')">###</a>

You will need to check each link with the alert because http://www.blah.com is different from www.blah.com, so check that the spelling is exact. You don't need to specify a target as the pages will load in the welcomeframe by default, if that's where you want them.

Of course you will have to have the function in every page that is loaded into the welcomeframe.
Copy linkTweet thisAlerts:
@rushie84authorJul 29.2003 — alright, i have 2 more questions (right now, at least).


1)what file are u indicating with:

('file:///C:/Documents%20and%20Settings/Owner/Desktop/mgb/JavaScript/menu2.html')?

and

2) when i put this function in the pages that load in the welcomeframe, do i need to call it with onLoad or onClick or anything like i do on the navigation page?
Copy linkTweet thisAlerts:
@SlankenOgenJul 29.2003 — That's just the file I used for testing. Replace it with the url you are using. The url will be sent to the function in the other frame so there is no need to create a normal link. That's why the hash is used.
Copy linkTweet thisAlerts:
@rushie84authorJul 29.2003 — ok, the links call up the pages in the 'welcomeframe', but the links are still clickable. i have put the function without alerts on the navigation page, and the function with alerts on every other page, including the frame page. the links are nullified and everything. is there something im leaving out? i really appreciate all of your help, and if u can't tell, im sort of new to JavaScript.
Copy linkTweet thisAlerts:
@SlankenOgenJul 30.2003 — The important line is

if(thisLink == document.links[k])

use an alert here to make sure they are exactly the same. If they are they should not load. You should not have the function in the links page, only in the welcomeframe pages.
Copy linkTweet thisAlerts:
@rushie84authorJul 30.2003 — i still can't get this to work. are the alerts just for testing purposes? theres one page where two alerts come up on exit with the url of two hyperlinks that i have within that particular page. all of the links are still clickable. I'll give you a couple examples of what i have right now. Its exactly what u told me to put, but i just want to make sure its right:

1)This is an example of the navigation page. the function is not in the header of this one, since u told me to take it out:

<a href="#" onClick="return parent.frames['welcomeframe'].checkLinks('yourhealth.html')">About Your Health</a>

2)This is what i have in the 'yourhealth.html' page:

function checkLinks(thisLink){

var lgn = document.links.length;
var k = 0;

for(k = 0; k < lgn; k++){
alert(document.links[k]);
if (thisLink == document.links[k]){
alert(thisLink+ " is on this page also.");
return false;
}
}
document.location.href = thisLink;
return;

}

I'm not sure why its not working. everything looks right. If u have some more ideas, please let me know. I appreciate it.
Copy linkTweet thisAlerts:
@SlankenOgenJul 30.2003 — Yes, the alerts are just for testing. You must make sure the alert shows exactly the same url as the one being sent to the function. It works fine for me. But do I understand you correctly? I have it so that the links in the navigation page are nullified if they exist in the welcomeframe, but the links in the welcomeframe will work anyway.
Copy linkTweet thisAlerts:
@rushie84authorJul 30.2003 — Again, i appreciate all your help. you are talking about links in the welcomeframe. i didn't put any links in the welcomeframe. the only links i am concerned with are in the navigation page and they bring up a page in the welcomeframe. theres two pages that come up in the welcomeframe that have links on them, and these two pages are the only ones that bring up a message box.

does that help any, or is that what you were saying to begin with?
Copy linkTweet thisAlerts:
@SlankenOgenJul 30.2003 — It should work then. You want the links in the navigation to be nullified? Is this correct?

If you post the html + javascript for the navigation frame and a welcome page I'll have a look.
Copy linkTweet thisAlerts:
@rushie84authorJul 30.2003 — Correct. I would like link for the page that is showing in the welcomeframe to be nullified.

1)Navigation Page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head><link rel="STYLESHEET" type="text/css" href="externalstylesheet.css">

<title>Navigation</title>

<script language="javascript">
<!--
Nav4 = (document.layers) ? 1:0;
IE4 = (document.all) ? 1:0;
//-->
</script>

<style type="text/css">
<!--
a{font-size: 16px;}
a:active{color: #FF0000;}
#pic{position: relative; left: 42px; top: 10px; z-index: 0;}
//-->
</style>


</head>

<body bgcolor="#000000">

<font color="#ADD8E6">

<div ID="pic"><img src="../images/sprayfront.jpg" align=center height=80px width=100px alt="Spray"></div><br>

<center>2003<br>Water Quality<br>Report<br></center>


<ul>

<li>

<a href="#" onClick="return parent.frames['welcomeframe'].checkLinks('welcome.html')">Welcome</a>

<p>

<li>

<a href="#" onClick="return parent.frames['welcomeframe'].checkLinks('contactus.html')">Contact Us</a>

<p>

<li>

<a href="#" onClick="return parent.frames['welcomeframe'].checkLinks('boardmembers.html')">Our Board</a>

<p>

<li>

<a href="#" onClick="return parent.frames['welcomeframe'].checkLinks('yourhealth.html')">About Your Health</a>

<p>

<li>

<a href="#" onClick="return parent.frames['welcomeframe'].checkLinks('labresults.html')">Water Quality Data</a>

<p>

<li>

<a href="#" onClick="return parent.frames['welcomeframe'].checkLinks('montgnd.html')">Non-Detects</a>

<p>

<li>

<a href="#" onClick="return parent.frames['welcomeframe'].checkLinks('additionalinfo.html')">Additional Information and Terms</a>

<p>

<li>

<a href="#" onClick="return parent.frames['welcomeframe'].checkLinks('sourcewater.html')">Source Water Assessment Reports</a>

<p>

<li>

<a href="#" onClick="return parent.frames['welcomeframe'].checkLinks('murphyhouse.html')">The Historic Murphy House</a>

<p>

<li>

<a href="#" onClick="return parent.frames['welcomeframe'].checkLinks('watersource.html')">Where Your Water Comes From</a>

<p>

<li>

<a href="#" onClick="return parent.frames['welcomeframe'].checkLinks('rollhnd.html')">Rolling Hills</a>

<p>

<li>

<a href="#" onClick="return parent.frames['welcomeframe'].checkLinks('specialthanks.html')">Special Thanks</a>

<p>

<li>

<a href="http://www.mwwssb.com" target="_parent">Montgomery Water Works Website</a>

</ul>

<p>

<center><a href="MAILTO:[email protected]"

onMouseOver="window.status='E-mail the webmaster!';return true;" onMouseOver="changeText(this)" onMouseOut="window.status='';return true;" onMouseOut="changeTextBack(this)"><img src="../images/email.jpg" style="border:0"> E-mail Us!</a>

</body>

</html>


2) This is the "contact Us" page that will show up in the welcomeframe:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head><link rel="STYLESHEET" type="text/css" href="externalstylesheet.css">

<title>Montgomery Water Works 2003 Water Quality Report | Contact Us</title>

</head>

<script language="javascript">

<!--

Nav4 = (document.layers) ? 1:0;

IE4 = (document.all) ? 1:0;

function checkLinks(thisLink){

var lgn = document.links.length;
var k = 0;

for(k = 0; k < lgn; k++){
alert(document.links[k]);
if (thisLink == document.links[k]){
alert(thisLink+ " is on this page also.");
return false;
}
}
document.location.href = thisLink;
return;
}


function changeText(whichEmail){
if (Nav4) {return}
whichEmail.style.fontSize="14pt";
whichEmail.style.color="#FFFFFF";
}
function changeTextBack(whichEmail){
if (Nav4) {return}
whichEmail.style.fontSize="12pt";
whichEmail.style.color="#ADD8E6";
}
//-->
</script>



<meta http-equiv="Page-Exit" content="RevealTrans(Duration=2,Transition=3)">

<body bgcolor="#000000">

<h4><center>Contact Info</h4>

<br>

<table bgcolor="#000000" cellpadding=10>

<tr>

<td valign=top align=center><font size=+1 color="#ADD8E6"><b>Who?<td valign=top align=center><font size=+1 color="#ADD8E6"><b>Where?<td valign=top align=center><font size=+1 color="#ADD8E6"><b>How?</font></b>

<tr>

<td valign=top align=center><font color="#FFFFFF">Thomas R. Morgan,

<br>

General Manager

<td valign=top align=center><font color="#FFFFFF">

22 Bibb Street

<br>

Montgomery, AL 36104

<td valign=top align=center><font color="#FFFFFF">

(334) 206-1600

<br>

<a href="http://www.mwwssb.com" target="_blank">www.mwwssb.com</a>

<br>

<a href="MAILTO:[email protected]"

onMouseOver="window.status='E-mail the webmaster!';return true;" onMouseOver="changeText(this)" onMouseOut="window.status='';return true;" onMouseOut="changeTextBack(this)">[email protected]</a>

</table>

<br>

<table>

<tr>

<td>

<img src="../images/duckie.jpg" onMouseOver="window.status='Lindsey - Duckie - Grade 11';return true" onMouseOut="window.status='';return true" alt="Lindsey - Duckie - Grade 11">

<tr>

<td align=center><font color="#FFFFFF">

<b>Lindsey | <font color="#ADD8E6"><i>Duckie</i></font> | Grade 11</font></b>

</table>


</body>

</html>


I hope this helps. Thank you!
Copy linkTweet thisAlerts:
@SlankenOgenJul 30.2003 — Correct. I would like link for the page that is showing in the welcomeframe to be nullified. [/QUOTE]

The link in the navigation page?
Copy linkTweet thisAlerts:
@SlankenOgenJul 30.2003 — If the links in the welcomeframe pages are absolute links so too must be your arguments in the function call because this line-

if (thisLink == document.links[k])

is testing for a string and the comparison must be exact. For example if you send "welcome.html" as an argument and the actual link is

http://www.blah.com/welcome.html the comparison operator will return false because the 2 urls are not the same. If all your links are absolute (ie. with http://www.............) you will need to send absolute links like this-

<a href="#" onClick="return parent.frames['welcomeframe'].checkLinks('http://www.yourSite.com/sourcewater.html')">Source Water Assessment Reports</a>

The urls as send must match exactly those in the pages.
Copy linkTweet thisAlerts:
@rushie84authorJul 30.2003 — I see. I'm gonna try that and get back to you tomorrow, probably. Thanks again and i'll let you know.
Copy linkTweet thisAlerts:
@rushie84authorJul 31.2003 — my pages aren't linked yet, so i tried ('file:///g|/ccr2003/pages/welcome.html') this format for all the links, and i still can't get it to work. I'm gonna still work on it, and if you think of anything that i should check, please let me know. thanks
×

Success!

Help @rushie84 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...