• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with Target Attribute

 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am testing the "target=" attribute of <a> and <form>:

web page
<body>
<a href="../img/img1" target="images_win">load image 1 </a>
<form action="../img/img1" target="images_win" method=get>
<input type=submit />
</form>
</body>

If I submit the form, the image is loaded in a new window as expected. However, if I click the link, the image is unexpectedly loaded in the current window (replacing the current content) instead of going into a new one. Did I make any mistake? I tested the page under IE6 WinXP. Is it a bug of IE ?
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I tested the page under IE6 WinXP. Is it a bug of IE ?



Did you get any chance to test in any other browsers like Opera, Firefox?
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


In the form tag, shouldn't the value of the action tag be a URL to a script to handle the pressing of the button?

It seems like it would be clearer if the image file, img1 had an extension, such as .gif, or .jpg.

I believe that links, using the <a element are easier, but the <form element opens you up to dynamic websites that can be programmed and you have a lot more power to draw from.

Kaydell
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try -

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kaydell Leavitt:


In the form tag, shouldn't the value of the action tag be a URL to a script to handle the pressing of the button?



Why? No script is necessary to use the target attribute.
[ July 30, 2007: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kaydell Leavitt:
It seems like it would be clearer if the image file, img1 had an extension, such as .gif, or .jpg.
[/QB]



I assume from the URL that the resource is a servlet that is serving the image data. No extension is necessary as long as the content type header is set correctly by the servlet.
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could anyone click the just link I provided and advise me the result (picture in a new or current window) and the browser you are using?
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alec, I clicked your link. In MSIE 7, I get a javascript error that states that the "object doesn't support the property or method" (I'm set up with a javascript debugger, so I get the errors in popup). The javascript source code is coming from [LINK]http://us.geocities.com/js_source/geovck08.js[/LINK]. This may be part of your trouble. Once I ignore the error, the image does pop up in a separate page.

However, with Firefox, the javascript is ignored completely and the image appears in the same page. You would be far better off placing the image's <img> tag inside of another page so that the link works properly since the anchor tag really was not designed to be used for images. It will accept any source code, but it won't necessarily follow the rules. HTML can be very forgiving, and you just happened to hit once of the things that it will alow you to do, although perhaps not the way you'd like it to happen.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My results:

In Firefox, Safari and Camino: cute kitty picture in new window (or tab)

In Opera: cute kitty picture in same window

All tested on a Mac.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In IE6 the cute kitty picture loads in the same window. What about trying target="_blank". As far as I know, it guarantees a new window.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic