disabled javascript workaround?

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Westerberg

Thread Starter
Joined
Sep 8, 2003
Messages
72
I have written some javascript into a web page This code causes a new page to open in a smaller window when a link is clicked. Here is an example of the code:

<html>
<head><title></title>
<script type="text/javascript">
<!--
function somepage()
{
window.open('somepage.html','somepage','width=400,height=300,resizable=yes')
}
//-->
</script>
</head>
<body>
<a href="javascript:somepage()">Click here!</a>
</body>
</html>

This works ok, but not all visitors to my page will have javascript enabled. For those visitors, rather than having them click the javascript link and get no result, I would like the link to open as a regular HTML link would, i.e., as a new page in the same browser window. Is there any way to accomplish this while preserving the javascript link for those who have it enabled? Thanks in advance for any help.
 
Joined
Apr 30, 2005
Messages
3,012
The easiest way is to have both:

<a href="javascript:somepage()">Open page in new window</a> | <a href="somepage.html">Open page in same window</a>

(the | is optional, it just looks nice when the two links are side-by-side)
 
Joined
Jul 8, 2002
Messages
14,681
Use the <noscript> tag to provide a link to users without JavaScript.
Use target="_blank" in your <a> tag to have it open in a new window.
 

Westerberg

Thread Starter
Joined
Sep 8, 2003
Messages
72
Thanks. The <noscript> tags worked after some modification.

You have to make sure you write the initial "Click here!" text using javascript. Otherwise, if javascript is disabled, you'll get back-to-back links, only one of which will work.


<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
<!--
function somepage()
{
window.open('somepage.html','somepage','width=400,height=300,resizable=yes')
}
//-->
</script>
</head>
<body>

<script language="JavaScript" type="text/javascript">
<!--
document.write('<a href="#","onClick="somepage()">Click here!</a>')
//-->
</script>
<noscript><a href="somepage.html">Click here!</a></noscript>
</body>
</html>

If someone has an alternative way to do this I'd like to hear about it.
 
Joined
Jul 8, 2002
Messages
14,681
You can still have it open in a new window by making your link like this
<a href="somepage.html" target="_blank">
 

Westerberg

Thread Starter
Joined
Sep 8, 2003
Messages
72
Thanks. I don't want it to open in a new browser. I guess I didn't make that clear. Thanks for the info. :)
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top