Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

window.open problem

Posted on 2004-09-24
14
Medium Priority
?
2,640 Views
Last Modified: 2008-02-07
I have a simple javascript

<a href="javascript:window.open('http://www.google.com');">Link</a>

But each time i click this link my main browser change to

[object]

why is this happenning ? how to prevent it ?

Thank you
0
Comment
Question by:fkmfkm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
  • +3
14 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 500 total points
ID: 12148981
Hi fkmfkm,

Try this:

<a href="#" onclick="window.open('http://www.google.com');return false;">Link</a>

Regards,
Zyloch
0
 
LVL 14

Expert Comment

by:boonleng
ID: 12149117
Or this to avoid the link from execute.

<a href="javascript:void(0)" onclick="window.open('http://www.google.com');return false;">Link</a>

Regards.
Boon Leng
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12149120
Just as clarification, boonleng is using javascript:void(0) which under normal circumstances, will do nothing, if the user has Javascript on or off. This is recommended if you want that. I used #, which will bring the user back to the top of the page if they have Javascript disabled. If the user has Javascript enabled however, both will be the same because of the return false;

Whew, a bunch of philosophical ideas there =)

Regards...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 36

Expert Comment

by:Zyloch
ID: 12149125
As a side note, because of the way this behaves, you can test the user for Javascript:

<a href="nojavascript.html" onclick="window.location.href='somewhere.html';return false;">Visit Our Site that needs Javascript.</a>

If the user has Javascript, onclick will fire, but if not, they will be taken to nojavascript.html

Regards...
0
 

Author Comment

by:fkmfkm
ID: 12149127
Zyloch

I get error
'return' statement outside of function.

Boon Leng

I want the link to work....
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12149134
My first one was tested on IE6 and Mozilla Firefox 0.9.3

If you don't believe, open up Notepad, just plop this:

<a href="#" onclick="window.open('http://www.google.com');return false;">Link</a>

in there, save as an html document, and open it.
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12149135
Of course, make sure your Javascript is enabled also.
0
 
LVL 14

Expert Comment

by:boonleng
ID: 12149251
Both mine and Zyloch code works :)
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12149552
The error "return outside..." you get for this version:

<a href="javascript:window.open('http://www.google.com');return false">Link</a>

0
 
LVL 25

Expert Comment

by:devic
ID: 12149981
in colection:
<a href="javascript:void(window.open('http://www.google.com'));">Link</a>
0
 
LVL 15

Expert Comment

by:Thogek
ID: 12152316
First of all, is there a reason you're using JavaScript for this link?  Your posted code above isn't doing anything to control the size of the new window, so it seems you could get much the same effect with something simpler like:

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

If you are controlling aspects of the new windows that you just didn't include above,...
Just as another marble to roll around in the ring, I personally tend to like:

    <a href="http://www.google.com/" onclick="window.open(this.href, '_blank'); return false;">Link</a>

That way, the link works and goes to the correct page regardless of whether JavaScript is currently supported, but will do so by way of a new window if JavaScript is supported.
0
 

Author Comment

by:fkmfkm
ID: 12157354
Opps...

My mistake..Zvonko pointed it to me...some typo error...

Too bad i just can accept one solution.Zyloch one cause he gave the first solution. You guys have been great.

Thogek you also have a nice solution.

thanks..
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12157367
You can choose assisted answers. It's Split Points by this comments box
0
 
LVL 15

Expert Comment

by:Thogek
ID: 12157812
Some people just don't read instructions, eh?  ;-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question