|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
||||
|
||||
|
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 |
|
#2
|
||||
|
||||
|
I just realized that it can be simpler to do this with php. I'm going to find out how, thanks anyway.
Cheers, Spongy |
|
#3
|
||||
|
||||
|
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 |
|
#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. |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
||||
|
||||
|
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 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Replacing target with an onClick |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|