473,326 Members | 2,023 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,326 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 3687
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.