473,385 Members | 1,780 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,385 software developers and data experts.

Overriding target attribute

First, a disclaimer: I am a librarian by trade, but have the responsibility of maintaining/updating our online catalog. I've dealt with some JavaScript before, but I am no expert, so please forgive my ignorance.

Question: Our automation system creates information dynamically for us. In one particular area of our page, it is adding a target=_self attribute that I believe is causing problems with our attempt at making a tab display. My theory is that if I can get this attribute changed to _blank, it might work, but I haven't figured out a way to do this. I have tried the following:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. / * Checks for target attribute in link tags. */
  3. var f=window.document.links;
  4. var i=f.length
  5. while(i--){
  6.      f[i].target='_blank'
  7. }
  8. </script>
  9.  
(the above was modified from another posting on this forum)

However, this does not seem to work because the link is still going to the _self target. Any suggestions would be greatly appreciated. Thank you!

Jamen McGranahan
Feb 13 '08 #1
1 1539
please forgive my ignorance.
Forgiven!

Question: Our automation system creates information dynamically for us.
You're talking server-side scripting -- like ASP or PHP? Or is this more of like a batch program to roll up a database into static html files?

In one particular area of our page, it is adding a target=_self attribute that I believe is causing problems with our attempt at making a tab display.
Please elaborate on "tab display"

My theory is that if I can get this attribute changed to _blank, it might work,
target is generally used with framesets -- if you have multiple frames, setting the "target" on an anchor will make the link open up in that frame... _blank usually means new page, _top means at the top level, above all the frames ... and most anything else -- i think, not sure -- if not found, the browser will open a new window and reference it by that name.

"target" has been depricated in html4.01 strict.

but I haven't figured out a way to do this. I have tried the following:
Expand|Select|Wrap|Line Numbers
  1. / * Checks for target attribute in link tags. */
  2. var f=window.document.links;
  3. var i=f.length
  4. while(i--){
  5.      f[i].target='_blank'
  6. }
  7.  
*winces* -- that'll set 'em all... or raise an error... or something... try this:

[html]<body onLoad="messWithAnchors( '_blank', '_self' )">[/html]
Expand|Select|Wrap|Line Numbers
  1. function messWithAnchors( _incomingTarget, _outgoingTarget ) {
  2.   var a = document.getElementsByTagName("A");
  3.   for(x=0;x<a.length;x++) {
  4.     if ( a[x].getAttribute( "target") == _incomingTarget ) {
  5.       a[x].setAttribute("target", _outgoingTarget );
  6.     }
  7.  
  8.     // test function to verify the target was set properly
  9.     // a[x].onclick = function() { alert(this.target); }
  10.   }
  11. }
  12.  
but anyway... back to my first question, if this is being generated automatically somehow, it would be WAY easier and more efficient to change the root source than it would be to wait for the document to load and change all the anchors' targets via javascript.
Feb 14 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dietmar Gräbner | last post by:
Hi Right now I'm dealing with derivation by restriction and I have some questions concerning the attribute property use in context of the derivation. Consider following Schema: <xs:schema...
24
by: Mike | last post by:
Hello How do i get around target="_blank" is not allowed in xtml strict? Thanks Mike
16
by: Mark van Ballegooijen | last post by:
When using the XHTML 1.0 validator at http://validator.w3.org/check, an error will be raised for every instance of a "target" attribute in "A" elements. Is it truely because it is not part of this...
36
by: randau | last post by:
I would like to use the Link Target attribute, but am inhibited by the likelihood of a newly opened browser window completely hiding the Parent browser window. Thus offering the illusion that...
2
by: ESPNSTI | last post by:
Hi, I'm very new to C# and .Net, I've been working with it for about a month. My experience has been mainly with Delphi 5 (not .Net). What I'm looking for is for a shortcut way to override a...
1
by: Joe | last post by:
I have a web.sitemap file that has the url title and description. I then have this attac attached to a menu. I want some of my menu choices to open up in a page in a new window ie _blank as...
4
by: Raja Raman Sundararajan | last post by:
Hello guys, I have data stored in the database which has special characters like <, etc. Case 1: Whenever I wanted to present the output to a browser I need to escape these special characters...
10
by: r035198x | last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize. These were designed to be overridden according to specific general contracts. Other classes that...
92
by: Erwin Moller | last post by:
Hi group, I encoutered page validation error, but I don't know a way around. The page has the following doctype: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.