Solved

OnClick to open in same window?

Posted on 2002-03-12
12
1,315 Views
Last Modified: 2008-01-09
How must I chnage this code to get this ref to open in the same window or at least close the calling window. I do not wnat the full path to display. That is why I am using the "href=#". Here is my code:


...............
<a href=# onClick="window.open('http://gisweb/liquor_license/secret/index.htm')" ><img src="button2.gif" height="15" width="15" border="0" alt="Edit Liquor License Database" align="middle">
.......
0
Comment
Question by:apwbe
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 30

Expert Comment

by:third
ID: 6859169
how about,

<a href="http://gisweb/liquor_license/secret/index.htm" onmouseover="window.status='click here...';" onmouseout="window.status='';"><img src="button2.gif" height="15" width="15" border="0" alt="Edit Liquor License Database" align="middle"></a>
0
 
LVL 23

Accepted Solution

by:
b1xml2 earned 100 total points
ID: 6859177
<a href=# onClick="window.open('http://gisweb/liquor_license/secret/index.htm','_same')" ><img src="button2.gif" height="15" width="15" border="0" alt="Edit
Liquor License Database" align="middle"></a>
.......

the window.open method has three widely params
<url>,<name>,<features>

you by specify the name (the same for all the links with your struct) so that the same window will be re-used
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 6859179
hehehe third, we meet again!!!
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 30

Expert Comment

by:third
ID: 6859217
hehehe it's a small world!

i'm thinking also the same with you but i realized he stated he don't wanna display the full path so i think he is referring to the status bar display. anyway, both code works! ;-)
0
 

Author Comment

by:apwbe
ID: 6859237
Third,

I could not get yours to work.

b1xml2,

I got you chnage to work but had to change the "_same" to "_top" and it works like I wnated it to.

Thanks guys
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 6859283
the _same is a string, it could be any name, doesnt matter!
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 6859623
This shows that what you have asserted is incorrect. The name of the window is a STRING and it doesnt matter what the STRING value is except that it must be the same.

<html>
<head>
<title>Reusable Window</title>
</head>
<body>
<a href="#" onclick="window.open('http://www.microsoft.com','_same')" ><img src="../images/collapse.gif" border="0" alt="Microsoft.COM" align="middle"></a>
<a href="#" onclick="window.open('http://www.ibm.com','_same')" ><img src="../images/collapse.gif" border="0" alt="IBM.COM" align="middle"></a>
<a href="#" onclick="window.open('http://www.cisco.com','_same')" ><img src="../images/collapse.gif" border="0" alt="Cisco.COM" align="middle"></a>
</body>
</html>

Any expert can test this with NS4.x,MSIE4+(4 or higher), NS6.x and will find the window re-usable.

I object also to the grade B.
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 6859629
and may I add, the list of black-listed users by me has just grown by 1 today!
0
 
LVL 30

Expert Comment

by:third
ID: 6859638
i do agree with you, b1xml2. you deserve an A.


another workaround would be,

<a href="#" onclick="window.location='http://www.google.com';return false;">
<img src="button2.gif" height="15" width="15" border="0" alt="Edit Liquor License Database" align="middle"></a>

0
 
LVL 23

Expert Comment

by:b1xml2
ID: 6859644
thank you, third for your independent verification =)))
0
 

Author Comment

by:apwbe
ID: 6862005
Sorry if I offended anyone as I am no expert and you guys are. Please accept my apology. All I know is that changing the _same string to _top made the code work the way I wanted it to. Most likely operator error or something I did not notice.

Thanks again.

ps

b1xml2,

Please explain the black_listed users comment. I certainly did not intend to insult someone with my acceptance of your answer. Do you mean that I am suppose to give the expert an automatic A if I accept their answer or do you mean that if you do not get an A you do not want to play?
0
 

Expert Comment

by:reallynicejerk
ID: 7340433
b1xml2, if I'm not mistaken you're simply confused about what he was trying to do.

Your link opens in a new window which is then reused everytime a link is opened with that same window name.  This is basic HTML linking and is carried through into javascript. There is no need for the underscore in the page title although it still works. The only underscore titles that are recognized by browsers are _blank _parent _self and _top.  

However, what apwbe was trying to do was use onclick to open a link in the current browser window. The targets _parent _self and _top would do so as long as he was not using frames. If he was using frames the only target title that would work would be _self. _parent would open the browser in the parent frameset and _top would open in the same browser window without any framesets above it.

Third's answer of using window status to solve the problem was even more off of what he was trying to do, and isn't effective as 1 users can simply right click on the link to reveal the url, 2, many third party browser plugins disable altering of the status bar and 3, window.status only works in internet explorer as far as I know (atleast it doesn't work in my versions of Netscape, Mozilla, Opera, or any of the other browsers that came with redhat linux 8.0 (I never really paid attention to their names, just tried them out a few times)).

Not to step on anyone's toes here, but I have to say that I agree with the grade of the B as the whole point of the question was to find out how to use onclick to open in the same window, you simply told him how to use onclick.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now