473,402 Members | 2,064 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,402 software developers and data experts.

<a href="javascript"> ??

Hi,

I'm currently writing:
<span onclick="window.open(...);">Klick Here</span>

but I want to use the <a href> for this, since it is defined in the
css script the way I want my link to open. Now, if I use a href, the
href will be executed as well. What can I du in order to make the href
not execute if javascript is enabled?
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
Jun 26 '06 #1
10 3693
Gernot Frisch wrote on 26 jun 2006 in comp.lang.javascript:
Hi,

I'm currently writing:
<span onclick="window.open(...);">Klick Here</span>

but I want to use the <a href> for this, since it is defined in the
css script the way I want my link to open. Now, if I use a href, the
href will be executed as well. What can I du in order to make the href
not execute if javascript is enabled?


onclick="window.open(...);return false;"

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 26 '06 #2
Gernot Frisch wrote:
Hi,

I'm currently writing:
<span onclick="window.open(...);">Klick Here</span>

but I want to use the <a href> for this, since it is defined in the
css script the way I want my link to open. Now, if I use a href, the
href will be executed as well. What can I du in order to make the href
not execute if javascript is enabled?


I think the commonly accepted way is to use the following:

<a href="NoJSError.html" onclick="window.open(...); return false;">
Klick Here
</a>

After window.open(...) is executed, return false; will make sure thet
the default action to follow the link is not executed.

If there is no JS available, the NoJSError.html will be shown, explaining
that JavaScript needs to be enabled for your site to work properly.

NOTE:
Even if JS is enabled, if "window.open(...);" fails for some reason,
the "return false;" will not be executed, and the href will be followed.

--
Dag.





Jun 26 '06 #3
Gernot Frisch wrote:
What can I du in order to make the href
not execute if javascript is enabled?


http://www.javascripttoolbox.com/bestpractices/#onclick

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jun 26 '06 #4
Rik
Dag Sunde wrote:
NOTE:
Even if JS is enabled, if "window.open(...);" fails for some
reason, the "return false;" will not be executed, and the href
will be followed.


Which is why is it's good practise to create proper links, that will make
the page work without javascript (possibly a server-side script and for
instance GET variables). It's twice the coding, but a great accessible page.
My practise normally is;
1. Make the page work without any javascript.
2. Add javascript where usefull to prevent unneccessary page-loading.

Unfortunately, not all uses of javascript can be handles this way, but a lot
can, and should.

Grtz,
--
Rik Wasmus
Jun 26 '06 #5
Which is why is it's good practise to create proper links, that will
make
the page work without javascript (possibly a server-side script and
for
instance GET variables). It's twice the coding, but a great
accessible page.
My practise normally is;
1. Make the page work without any javascript.
2. Add javascript where usefull to prevent unneccessary
page-loading.

Unfortunately, not all uses of javascript can be handles this way,
but a lot
can, and should.


full ACK. I want the href to point to the exact same locatino, but use
JS for opening it in a popup window (it's a bible-verse reference
automatism for a forum, like: [bible=gen:1,1], that will create a
small image and a clickable link)

Thank you very much!
Jun 26 '06 #6
Gernot Frisch said the following on 6/20/2006 10:17 AM:
Which is why is it's good practise to create proper links, that will
make
the page work without javascript (possibly a server-side script and
for
instance GET variables). It's twice the coding, but a great
accessible page.
My practise normally is;
1. Make the page work without any javascript.
2. Add javascript where usefull to prevent unneccessary
page-loading.

Unfortunately, not all uses of javascript can be handles this way,
but a lot
can, and should.


full ACK. I want the href to point to the exact same locatino, but use
JS for opening it in a popup window (it's a bible-verse reference
automatism for a forum, like: [bible=gen:1,1], that will create a
small image and a clickable link)

Thank you very much!


<a href="bibleVerse.html" target="_blank"
onclick="window.open(this.href,this.target);return false">
Bible Verse
</a>

There are still problems with it (the failure of window.open calls) but
using this.href and this.target are a beginning to not having to change
code in two places.

A better alternative would be onclick="return myFunction(this)">

Where myFunction would look up the href, the target, try to open a
window, and return true or false based on results.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 26 '06 #7
<a href="bibleVerse.html" target="_blank"
onclick="window.open(this.href,this.target);return false">
Bible Verse
</a>


Perfect!
Jun 27 '06 #8
Randy Webb a écrit :
<a href="bibleVerse.html" target="_blank"
onclick="window.open(this.href,this.target);return false">
Bible Verse
</a>

There are still problems with it (the failure of window.open calls) but
using this.href and this.target are a beginning to not having to change
code in two places.


What about :

<a href="bibleVerse.html" target="_blank">
onclick="return !window.open(this.href, this.target);">
Bible Verse
</a>

--
laurent
Jun 28 '06 #9
Laurent Vilday said the following on 6/28/2006 8:38 AM:
Randy Webb a écrit :
<a href="bibleVerse.html" target="_blank"
onclick="window.open(this.href,this.target);return false">
Bible Verse
</a>

There are still problems with it (the failure of window.open calls)
but using this.href and this.target are a beginning to not having to
change code in two places.


What about :

<a href="bibleVerse.html" target="_blank">
onclick="return !window.open(this.href, this.target);">
Bible Verse
</a>


It's better but still not fool-proof. It will still fail if you have one
of the outdated popup blockers that either redefine window.open or close
the window after it is opened.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 28 '06 #10

"Randy Webb" <Hi************@aol.com> schrieb im Newsbeitrag
news:R4******************************@comcast.com. ..
Laurent Vilday said the following on 6/28/2006 8:38 AM:
Randy Webb a écrit :
<a href="bibleVerse.html" target="_blank"
onclick="window.open(this.href,this.target);return false">
Bible Verse
</a>

There are still problems with it (the failure of window.open
calls) but using this.href and this.target are a beginning to not
having to change code in two places.


What about :

<a href="bibleVerse.html" target="_blank">
onclick="return !window.open(this.href, this.target);">
Bible Verse
</a>


It's better but still not fool-proof. It will still fail if you have
one of the outdated popup blockers that either redefine window.open
or close the window after it is opened.


Thank you. I need this just for a feature. If the browser does not
support it, after all it's just a feature.
Jun 29 '06 #11

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

Similar topics

19
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - I have <a href="javascript:somefunction()"what ... ?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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...
0
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...

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.