/    Sign up×
Community /Pin to ProfileBookmark

trim function

Hi

I have a html template and i want to insert a deeplink tag like this

[CODE]<a href='{deeplink}’>nice name</a>[/CODE]

because i want an output like this

[CODE]<a href=’http://www.url.com’>nice name</a>[/CODE]

When i do this the out put is like this

[CODE]<a href='<strong>Deeplink</strong>: <a href=”http://www.url.com” onclick=”window.open(this.href,’_blank’,’location=1,resizable=1,status=1,scrollbars=1,toolbar=1,menubar=1′);return false”>http://www.url.com</a><br />’>nice name</a>[/CODE]

How can i trim this code to get the results i mentioned before

Greetings
Jurgen

to post a comment
JavaScript

11 Comments(s)

Copy linkTweet thisAlerts:
@KorNov 08.2010 — Hi

I have a html template and i want to insert a deeplink tag like this

[CODE]<a href='{deeplink}'>nice name</a>[/CODE]

because i want an output like this

[CODE]<a href='http://www.url.com'>nice name</a>[/CODE]
[/QUOTE]

[I]Template[/I]? What kind of template? That problem looks to have nothing to do with HTML nor with JavaScript. It is [I]your[/I] "template" application, probably based on XML, which inserts something there, we don't know how, we don't know why.
Copy linkTweet thisAlerts:
@derksjauthorNov 10.2010 — My output is a fact

Its not a problem

I just try to look for a solution to make the output as i want it

with php i would use a trim function or something like that

but my templates is written in html so i only can use javascript
Copy linkTweet thisAlerts:
@KorNov 10.2010 — It seems like you don't understand how a template works. You need to find which template file generates that token and make the changes [I]there[/I]. No room for javascript or whichever. [I]It is a template's behavior[/I]
Copy linkTweet thisAlerts:
@derksjauthorNov 10.2010 — I now how a template works but i not want to change the file thats responsible for the behaviour because the behaviour is ok for all other tags

I only want to change this tag
Copy linkTweet thisAlerts:
@KorNov 10.2010 — Than change something in the structure of template files, change the templates tokens, do something related with the template's behavior.
Copy linkTweet thisAlerts:
@derksjauthorNov 10.2010 — Kor

I not want all that

I need just a piece of javascript that trims my output to the format i want for this specific tag
Copy linkTweet thisAlerts:
@KorNov 10.2010 — Kor

I not want all that

I need just a piece of javascript that trims my output to the format i want for this specific tag[/QUOTE]

It is not a matter of what you want, it is a matter of what [I]you should do[/I] and, most important, of what [I]is possible[/I]. What do you think javascript is: a panacea?

You can't do that with JavaScript. Your "deep link" builds an illegal DOM element, spoiling the HTML DOM standard syntax. Or JavaScript needs to work with a correct DOM structure in order to find a DOM element and to do whichever with it. No correct DOM structure? No possibility to use JavaScript in that document.
Copy linkTweet thisAlerts:
@MrRedNov 10.2010 — If the HTML code appears as you say then you can access it as part of the body somewhat like (check case sensitives)
var fred = self.body.innerHTML;
var fredonclick = fred.search(/onclick/);
var fredfalse = fred.search(/return false/);
self.body.innerHTML = fred.substring(0,fredonclick-1) + fred.substring(fredfalse+2);

after that you you are on your own, because it would still leave a clutter of "</a>" (etc) that you would still have to remove in a similar way (before returning it to innerHTML)

best of luck and try experimenting

I use FireFox with FireBug loaded. It helps a lot though always check against IE they do things differently sometimes.
Copy linkTweet thisAlerts:
@KorNov 10.2010 — [B]self.body[/B] presumes also a correct DOM structure, as body is also a DOM element. DOM reference won't work if the DOM structure is corrupted. Your solution might work, might not, depending on browser type. Furthermore, innerHTML is not a standard DOM method, it will not insert always the elements into the DOM tree.

JavaScript is not a server-side language. It is not able to "write" everything you want on the document.
Copy linkTweet thisAlerts:
@MrRedNov 11.2010 — Well - whenever I see the word "NO!" I reach for my Firebug.

There are more ways of skinning a cat, than choking it with cream and butter.

See how FF & IE react to dodgy HTML and go from there. You may need to test on many browsers/versions and write code for each.

Opera does adhere to standards so does funny things when you go outside the "correct ways". And they all have their foibles. Check against as many as you can.

AFAIK the innerHTML should remain as loaded - though it may render hash codes in plain text if it can. (hash codes can be used to get funny accented letter and fonts like Tamil & Cyrillic )

see

http://www.users.waitrose.com/~cresby/various/codes3.htm

and play to see examples & generate your own.
Copy linkTweet thisAlerts:
@KorNov 11.2010 — 
See how FF & IE react to dodgy HTML and go from there. [/QUOTE]

In my opinion that is a wrong approach to solve a problem. The fact that a browser [I]might[/I] do something, but incorrectly and ignoring the standards, should no be a starting point to solve a problem.

For instance: if a browser (IE) is able to take the [B]name[/B] attribute instead of an[B] id[/B], if the id is missing, that wrong behavior [I]should not be used[/I] as a base for a solution of a problem.

An error can not be the basis of a solution, right?

As far as I see, the OP's problem is that he does not know how to work with that Web Template, so he tries desperately to find a solution which would not oblige him to learn that application. A JavaScript solution to his problem would be nothing but a botch.
×

Success!

Help @derksj spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...