473,738 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overriding '<a href' with '<a onClick' for JavaScript function openWindow(URL) for image and link...

Hello,

Can anyone assist me with what I am trying to do with the following
code (six different scenarios to try to make the functionality work
correctly)?

I want to always (and ONLY) display in the status bar 'Symantec
Corporation' whenever anyone mouses over (onMouseOver) my image or
link OR when one clicks while holding the left mouse down (onClick) on
the same image or link. Upon releasing the mouse (onMouseOut), the
status bar should be 'blank'. I need the link to open in a new window
via my function openWindow(URL) code.

What is happening in most of the six scenarios, is that when one
clicks the link, either the function doesn't engage, but rather the <a
href= takes effect instead OR that status bar shows
'javascript:ope nWindow('http://www.symantec.co m/');' when one clicks
while holding the left mouse down (onClick) on the image or link.

Additionally, for only the link, I need the CSS/style to show 'red'
when one mouses over (onMouseOver) it and then change to 'blue' upon
releasing the mouse (onMouseOut).

How about integrating 'style="cursor: hand"' into the code or perhaps
setting some of the data via a <div> or <span> snippet?

Thanks much,

Paul

----------------------

<html>
<head>
<style type="text/css">a:link {text-decoration:unde rline;
color:blue;}a:v isited{text-decoration:unde rline; color:blue;}a:h over
{text-decoration:unde rline; color:red;}a:ac tive
{text-decoration:unde rline; color:blue;}</style>
<script language="JavaS cript">
function openWindow(URL) {
var availWidth = screen.availWid th + 1;
var availHeight = screen.availHei ght;
var x = 0, y = 0;
if (document.all) {
x = window.screenTo p;
y = window.screenLe ft;
}
else if (document.layer s) {
x = window.screenX;
y = window.screenY;
availWidth = availWidth - 11;
availHeight = availHeight - 155;
}
var arguments =
'resizable=yes, toolbar=yes,loc ation=yes,direc tories=yes,addr essbar=yes,scro llbars=yes,stat us=yes,menubar= yes,top=0,left= 0,screenX='+x+' ,screenY='+y+', width='+availWi dth+',height='+ availHeight;
var newWindow = window.open(URL ,'_blank',argum ents);
}
</script>
</head>
<body marginwidth="0" marginheight="0 " leftmargin="0" topmargin="0"
text="#333333" link="#336699" vlink="#336699"
alink="#990033" bgcolor="#99999 9">
<center>
<table>
<tr>
<td>
<b>First Scenario</b>
<a href="JavaScrip t:openWindow('h ttp://www.symantec.co m/');"
onMouseOver="wi ndow.status='Sy mantec Corporation';
return true;" onMouseDown="wi ndow.status='Sy mantec Corporation';
return true;" onMouseOut="win dow.status=''; return
true;"><img src="http://www.symantec.co m/images/downloads/product_shot.gi f"></a>
<a href="JavaScrip t:openWindow('h ttp://www.symantec.co m/');"
onMouseOver="wi ndow.status='Sy mantec Corporation';
return true;" onMouseDown="wi ndow.status='Sy mantec Corporation';
return true;" onMouseOut="win dow.status=''; return
true;">Symantec 1</a>
</td><td>&nbsp;&n bsp;</td><td>
<b>Second Scenario</b>
<a onMouseOver="wi ndow.status='Sy mantec Corporation'; return true;"
onMouseOut="win dow.status='Sym antec
Corporation'; return true;" onMouseDown="wi ndow.status='Sy mantec
Corporation'; return true;"
onClick="openWi ndow('http://www.symantec.co m/');"><img
src="http://www.symantec.co m/images/downloads/product_shot.gi f"></a>
<a onMouseOver="wi ndow.status='Sy mantec Corporation'; return true;"
onMouseOut="win dow.status='Sym antec
Corporation'; return true;" onMouseDown="wi ndow.status='Sy mantec
Corporation'; return true;"
onClick="openWi ndow('http://www.symantec.co m/');">Symantec2 </a>
</td><td>&nbsp;&n bsp;</td><td>
<b>Third Scenario</b>
<a onMouseOver="wi ndow.status='Sy mantec Corporation'; return true;"
onMouseOut="win dow.status=''; return true;"
onMouseDown="wi ndow.status='Sy mantec Corporation'; return true;"
onClick="openWi ndow('http://www.symantec.co m/');"
style="cursor:h and"><img
src="http://www.symantec.co m/images/downloads/product_shot.gi f"></a>
<a onMouseOver="wi ndow.status='Sy mantec Corporation'; return true;"
onMouseOut="win dow.status=''; return true;"
onMouseDown="wi ndow.status='Sy mantec Corporation'; return true;"
onClick="openWi ndow('http://www.symantec.co m/');"
style="cursor:h and">Symantec3 </a>
</td></tr>
<tr><td><b>Four th Scenario</b>
<a href="" onMouseOver="wi ndow.status='Sy mantec Corporation'; return
true;" onMouseOut="win dow.status=''; return
true;" onMouseDown="wi ndow.status='Sy mantec Corporation'; return
true;"
onClick="openWi ndow('http://www.symantec.co m/'); return true;"
style="cursor:h and"><img
src="http://www.symantec.co m/images/downloads/product_shot.gi f"></a>
<a href="" onMouseOver="wi ndow.status='Sy mantec Corporation'; return
true;" onMouseOut="win dow.status=''; return
true;" onMouseDown="wi ndow.status='Sy mantec Corporation'; return
true;"
onClick="openWi ndow('http://www.symantec.co m/'); return true;"
style="cursor:h and">Symantec4 </a>
</td><td>&nbsp;&n bsp;</td><td>
<b>Fifth Scenario</b>
<a href="#" style="text-decoration: none; cursor: default;"
onClick="return false;" onMouseOver="wi ndow.status=' ';return
true;"><img src="http://www.symantec.co m/images/downloads/product_shot.gi f"></a>
<a href="#" style="text-decoration: none; cursor: default;"
onClick="return false;" onMouseOver="wi ndow.status=' ';return
true;">Symantec 5</a>
</td><td>&nbsp;&n bsp;</td><td>
<b>Sixth Scenario</b>
<a onMouseOver="wi ndow.status='Sy mantec Corporation'; return true;"
onMouseOut="win dow.status=''; return true;"
onMouseDown="wi ndow.status='Sy mantec Corporation'; return true;"
onClick="openWi ndow('http://www.symantec.co m/');" style="a:link
{text-decoration:unde rline; color:blue;}
a:visited{text-decoration:unde rline; color:blue;} a:hover
{text-decoration:unde rline; color:red;} a:active
{text-decoration:unde rline; color:blue;}">< img
src="http://www.symantec.co m/images/downloads/product_shot.gi f"></a>
<a onMouseOver="wi ndow.status='Sy mantec Corporation'; return true;"
onMouseOut="win dow.status=''; return true;"
onMouseDown="wi ndow.status='Sy mantec Corporation'; return true;"
onClick="openWi ndow('http://www.symantec.co m/');" style="a:link
{text-decoration:unde rline; color:blue;}
a:visited{text-decoration:unde rline; color:blue;} a:hover
{text-decoration:unde rline; color:red;} a:active
{text-decoration:unde rline; color:blue;}">S ymantec6</a>
</td>
</tr>
</table>
</body>
</html>
Jul 23 '05 #1
2 9171
All,

First of all, I errored, I would prefer the status to show
'http://www.symantec.co m/' for onMouseOver and onClick instead of
'Symantec Corporation'.

After making some changes, by adding 'return false;' in the onClick
handler it is doing the trick for the '<a href=' portion!!

I have added this JavaScript line 'var hrefName =
"http://www.symantec.co m/";' to show how I need it enhanced. The
reason for this is because I am going to display a different
link/company depending upon other code in the file and need the '<a
href=' to reference a variable array of URLs.

In the meantime, all is now working with my additions but please see
the '<a href=hrefName' portion below.

How can I pass a JavaScript variable to the '<a href=' portion of the
HTML?

By the way, I am primarily interested in getting it to work correctly
for Internet Explorer.

------------------------------------------------------

<a href="http://www.symantec.co m/"
onClick="openWi ndow(hrefName); return false"
onMouseOver="wi ndow.status=hre fName"
onMouseDown="wi ndow.status=hre fName"
onMouseOut="win dow.status=''"> <img
src="http://www.symantec.co m/images/downloads/product_shot.gi f"></a>
<a href="http://www.symantec.co m/"
onClick="openWi ndow(hrefName); return false"
onMouseOver="wi ndow.status=hre fName;"
onMouseDown="wi ndow.status=hre fName"
onMouseOut="win dow.status=''"> Symantec10</a>
<a href=hrefName onClick="openWi ndow(hrefName); return false"
onMouseOver="wi ndow.status=hre fName"
onMouseDown="wi ndow.status=hre fName"
onMouseOut="win dow.status=''"> <img
src="http://www.symantec.co m/images/downloads/product_shot.gi f"></a>
<a href=hrefName onClick="openWi ndow(hrefName); return false"
onMouseOver="wi ndow.status=hre fName;"
onMouseDown="wi ndow.status=hre fName"
onMouseOut="win dow.status=''"> Symantec20</a>

------------------------------------------------------

Thanks much,

Kevin
ma*********@go. com (Kevin Lyons) wrote in message...
Hello,

Can anyone assist me with what I am trying to do with the following
code (six different scenarios to try to make the functionality work
correctly)?

I want to always (and ONLY) display in the status bar 'Symantec
Corporation' whenever anyone mouses over (onMouseOver) my image or
link OR when one clicks while holding the left mouse down (onClick) on
the same image or link. Upon releasing the mouse (onMouseOut), the
status bar should be 'blank'. I need the link to open in a new window
via my function openWindow(URL) code.

What is happening in most of the six scenarios, is that when one
clicks the link, either the function doesn't engage, but rather the <a
href= takes effect instead OR that status bar shows
'javascript:ope nWindow('http://www.symantec.co m/');' when one clicks
while holding the left mouse down (onClick) on the image or link.

Additionally, for only the link, I need the CSS/style to show 'red'
when one mouses over (onMouseOver) it and then change to 'blue' upon
releasing the mouse (onMouseOut).

How about integrating 'style="cursor: hand"' into the code or perhaps
setting some of the data via a <div> or <span> snippet?

Thanks much,

Paul

----------------------

<html>
<head>
<style type="text/css">a:link {text-decoration:unde rline;
color:blue;}a:v isited{text-decoration:unde rline; color:blue;}a:h over
{text-decoration:unde rline; color:red;}a:ac tive
{text-decoration:unde rline; color:blue;}</style>
<script language="JavaS cript">
function openWindow(URL) {
var availWidth = screen.availWid th + 1;
var availHeight = screen.availHei ght;
var x = 0, y = 0;
if (document.all) {
x = window.screenTo p;
y = window.screenLe ft;
}
else if (document.layer s) {
x = window.screenX;
y = window.screenY;
availWidth = availWidth - 11;
availHeight = availHeight - 155;
}
var arguments =
'resizable=yes, toolbar=yes,loc ation=yes,direc tories=yes,addr essbar=yes,scro llbars=yes,stat us=yes,menubar= yes,top=0,left= 0,screenX='+x+' ,screenY='+y+', width='+availWi dth+',height='+ availHeight;
var newWindow = window.open(URL ,'_blank',argum ents);
}
</script>
</head>
<body marginwidth="0" marginheight="0 " leftmargin="0" topmargin="0"
text="#333333" link="#336699" vlink="#336699"
alink="#990033" bgcolor="#99999 9">
<center>
<table>
<tr>
<td>
<b>First Scenario</b>
<a href="JavaScrip t:openWindow('h ttp://www.symantec.co m/');"
onMouseOver="wi ndow.status='Sy mantec Corporation';
return true;" onMouseDown="wi ndow.status='Sy mantec Corporation';
return true;" onMouseOut="win dow.status=''; return
true;"><img src="http://www.symantec.co m/images/downloads/product_shot.gi f"></a>
<a href="JavaScrip t:openWindow('h ttp://www.symantec.co m/');"
onMouseOver="wi ndow.status='Sy mantec Corporation';
return true;" onMouseDown="wi ndow.status='Sy mantec Corporation';
return true;" onMouseOut="win dow.status=''; return
true;">Symantec 1</a>
</td><td>&nbsp;&n bsp;</td><td>
<b>Second Scenario</b>
<a onMouseOver="wi ndow.status='Sy mantec Corporation'; return true;"
onMouseOut="win dow.status='Sym antec
Corporation'; return true;" onMouseDown="wi ndow.status='Sy mantec
Corporation'; return true;"
onClick="openWi ndow('http://www.symantec.co m/');"><img
src="http://www.symantec.co m/images/downloads/product_shot.gi f"></a>
<a onMouseOver="wi ndow.status='Sy mantec Corporation'; return true;"
onMouseOut="win dow.status='Sym antec
Corporation'; return true;" onMouseDown="wi ndow.status='Sy mantec
Corporation'; return true;"
onClick="openWi ndow('http://www.symantec.co m/');">Symantec2 </a>
</td><td>&nbsp;&n bsp;</td><td>
<b>Third Scenario</b>
<a onMouseOver="wi ndow.status='Sy mantec Corporation'; return true;"
onMouseOut="win dow.status=''; return true;"
onMouseDown="wi ndow.status='Sy mantec Corporation'; return true;"
onClick="openWi ndow('http://www.symantec.co m/');"
style="cursor:h and"><img
src="http://www.symantec.co m/images/downloads/product_shot.gi f"></a>
<a onMouseOver="wi ndow.status='Sy mantec Corporation'; return true;"
onMouseOut="win dow.status=''; return true;"
onMouseDown="wi ndow.status='Sy mantec Corporation'; return true;"
onClick="openWi ndow('http://www.symantec.co m/');"
style="cursor:h and">Symantec3 </a>
</td></tr>
<tr><td><b>Four th Scenario</b>
<a href="" onMouseOver="wi ndow.status='Sy mantec Corporation'; return
true;" onMouseOut="win dow.status=''; return
true;" onMouseDown="wi ndow.status='Sy mantec Corporation'; return
true;"
onClick="openWi ndow('http://www.symantec.co m/'); return true;"
style="cursor:h and"><img
src="http://www.symantec.co m/images/downloads/product_shot.gi f"></a>
<a href="" onMouseOver="wi ndow.status='Sy mantec Corporation'; return
true;" onMouseOut="win dow.status=''; return
true;" onMouseDown="wi ndow.status='Sy mantec Corporation'; return
true;"
onClick="openWi ndow('http://www.symantec.co m/'); return true;"
style="cursor:h and">Symantec4 </a>
</td><td>&nbsp;&n bsp;</td><td>
<b>Fifth Scenario</b>
<a href="#" style="text-decoration: none; cursor: default;"
onClick="return false;" onMouseOver="wi ndow.status=' ';return
true;"><img src="http://www.symantec.co m/images/downloads/product_shot.gi f"></a>
<a href="#" style="text-decoration: none; cursor: default;"
onClick="return false;" onMouseOver="wi ndow.status=' ';return
true;">Symantec 5</a>
</td><td>&nbsp;&n bsp;</td><td>
<b>Sixth Scenario</b>
<a onMouseOver="wi ndow.status='Sy mantec Corporation'; return true;"
onMouseOut="win dow.status=''; return true;"
onMouseDown="wi ndow.status='Sy mantec Corporation'; return true;"
onClick="openWi ndow('http://www.symantec.co m/');" style="a:link
{text-decoration:unde rline; color:blue;}
a:visited{text-decoration:unde rline; color:blue;} a:hover
{text-decoration:unde rline; color:red;} a:active
{text-decoration:unde rline; color:blue;}">< img
src="http://www.symantec.co m/images/downloads/product_shot.gi f"></a>
<a onMouseOver="wi ndow.status='Sy mantec Corporation'; return true;"
onMouseOut="win dow.status=''; return true;"
onMouseDown="wi ndow.status='Sy mantec Corporation'; return true;"
onClick="openWi ndow('http://www.symantec.co m/');" style="a:link
{text-decoration:unde rline; color:blue;}
a:visited{text-decoration:unde rline; color:blue;} a:hover
{text-decoration:unde rline; color:red;} a:active
{text-decoration:unde rline; color:blue;}">S ymantec6</a>
</td>
</tr>
</table>
</body>
</html>

Jul 23 '05 #2
Kevin Lyons wrote:
...
How can I pass a JavaScript variable to the '<a href=' portion of the
HTML?
...


Have a look at the following demo. Perhaps it will help.
http://cross-browser.com/toys/link_interception.html
Jul 23 '05 #3

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

Similar topics

3
3963
by: Mark Pacey | last post by:
Hi, I have a web page that gets info from a mySQL database for various items, and slaps that info, along with pics onto the page. ( in a shopping site stylee) The pics have an href link, and I want just one display page that all the pics refer to, so that any items pic and info can be viewed on its own. I therefore need a way of capturing the pic info into a session variable when the link is clicked, so that I can pull the individual item...
2
1425
by: magister | last post by:
Hello, Can anyone tell me with certainty? If I load a server-side image into a javascript image object. Is the image saved on the client, or does the page go back to the server when I do for instance an image swap? Thanks very much for feedback,
8
2276
by: Andrew Phillipo | last post by:
I have a layout which works perfectly. It is three column, the central column is width:auto; with margins and the columns are absolutely positioned at top:0px; left:0px; and top:0px;right:0px; In the right column I have a javascript link which hides the column. This is very necessary due to the width of content shown on the site at times. Clicking the link makes the scrollbars appear for no aparent reason - both horizontal by about...
5
3070
by: Ma³y Piotruœ | last post by:
Hello, (Sorry for my english.) I am new to HTML/JavaScript/CSS. I would like to ask for help with such a problem: I need to create a href link working like "back" button (I know this is not recommended by it's not my idea, and I must respect this requirement.) I did it this way: <a href="javascript:history.back()">Back</a>
3
2635
by: serge calderara | last post by:
Dear all, I have an application which display database result querry , store it in a dataset and bind a Datagrid control to it. I would like that the content of one particular column behaves like a HREF link. Then when my user clik on one records, it will jump to an other page dedicated to that item How to do that ?
1
1344
by: serge calderara | last post by:
Dear all, I have a wrb application wich reads data from an SQL database and store them in a dataset. The dataset is then attached to a datagrid object I need to have a functionnality that when a user click on any data of the first column it execute a HRef link. IN practical, when the user will click on the data, the value clicked will be pass to a second querry diplayed on an other page.
1
1462
by: Ma³y Piotruœ | last post by:
Hello, (I am sorry for my English, it is not my native language.) I am new to JavaScript. Could you help me please with the following problem?: I need to make a href link on HTML page that leads the user back to the previus page. I did it (accourding to downloaded course) this way: <a href="javascript:history.back()">Back</a> It doesn't work. Could you tell me plase and suggest correct solution? Thank you very much.
10
21583
by: pt36 | last post by:
Hi I have a page with a form and a textbox. before to submit the form I want to chek if the inserted value in the textbox is already present in a database. So I need to pass the textbox value by a javascript link to another page to check. my code is <a href="javascript:location.href='page_check.php' "Go check </a> and this work and open page_check.php
18
4059
by: requeth | last post by:
I'm trying to do the following, but when I have the code in for hte HREF link I get a runtime error. How do I pass the link to the end user? <% Dim a as string Dim b as string a = request.browser.browser b = "IE" if a <b then
0
8968
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8787
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9259
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.