SunQuest
 
           JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old April 19th, 2006, 10:27 AM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
Replacing target with an onClick

I have a question. I use TinyMCE for writing on a log, but when I create a link to another site in a new window, I get the non-XHTML compatible attribute 'target' in my link. I searched in TinyMCE for the line which created this attribute, but I couldn't find it. Now I want to replace the target-attribute in all my links on my site to an event (when they point to a "_blank" that is). That way the link ís XHTML-compliant and my pages will validate again.

I am a total noob with JS, so please don't laugh.
The code I have so far:
Code:
deleteTarget = function(){
		var targets, a, conta;
		
		a=document.getElementsByTagName('a');
		
		for(var i=0; i<a.length; i++){
				if(a[i].getAttribute('target')){
					a[i].removeAttribute('target');
					a[i].setAttribute('onClick', 'target=\"_blank\"');
				}
		}
}

Don't mind the useless variables...

Can somebody please help me?

Cheers,

Spongy
__________________
Work to live, don't live to work

Reply With Quote
  #2  
Old April 26th, 2006, 07:05 AM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
I just realized that it can be simpler to do this with php. I'm going to find out how, thanks anyway.

Cheers,
Spongy

Reply With Quote
  #3  
Old April 26th, 2006, 11:56 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
the Javascript is an interesting idea... nothing wrong with your code, it looks good.

I'm not sure what you plan to do with PHP though... keep us updated =)
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter!
DevArticles Forum Moderator

"The net is a waste of time, and that's exactly what's right about it." -- William Gibson

Reply With Quote
  #4  
Old April 26th, 2006, 10:19 PM
Kravvitz Kravvitz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Location: USA
Posts: 134 Kravvitz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 38 m 30 sec
Reputation Power: 4
The validators don't have a JavaScript parser in them.

That JavaScript code won't work anyway. You can't add events via setAttribute() in all browsers with DOM1+ support. setAttribute() takes two strings as arguments. Events are functions, not strings. setAttribute() doesn't convert the 2nd argument, which is the attribute's value, to a function in all browsers with DOM1+ support. Thus you should use DOM0 and/or DOM2 events, except that IE5+ uses its own event model instead of the DOM2 Event model.

Reply With Quote
  #5  
Old April 30th, 2006, 10:09 PM
ravs ravs is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Location: gurgaon, haryana, india
Posts: 60 ravs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 44 m 29 sec
Reputation Power: 3
Send a message via Yahoo to ravs
hey hey spongy dont do this .

you will never able to find the solution.

if u want to do this then do it like this. this not the full solution but u will find the way


var a=""
for()
{
a+="<a href='"+LINK+"' target='"+ TARGET +"' id='"+some sensible id+"'>"
}

document.body.innerHTML+=a;

some time we have to twist our finger the pull out butter from jar.

hope this will help u.

Reply With Quote
  #6  
Old April 30th, 2006, 10:38 PM
ravs ravs is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Location: gurgaon, haryana, india
Posts: 60 ravs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 44 m 29 sec
Reputation Power: 3
Send a message via Yahoo to ravs
Exclamation

you can do one more thig


var a = document.createElement("a");
a.href=""//link
a.target=""//give target
i did'nt used this but hope this may work.

Reply With Quote
  #7  
Old May 11th, 2006, 05:02 AM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
Thanks for the effort ravs, didn't totally got what you were doing unfortunately. Your code needs a lot of extension for my purposes, so I decided to do it with php.

For all who want to help my php-wise, I opened a thread in the php section here.

I'm at a dead point with my code. Hopefully someone wise will come and help me ;-)

Cheers,
Spongy

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Replacing target with an onClick


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway