Thanks. I really love you guys.
I ended up with this:
[CODE=javascript]mystr.replace(/((https?|ftp):\/\/[^\s]+)/g, '<a href="$1">$1</a>');[/CODE]
Which is enough for my needs.
User Profile
Collapse
-
Is it possible to write reg.expression for such a replace?
My problem:
My users will write some text into <textarea> area. All I want to do with javascript is to take that textarea.value and replace all url links there with regular <a href> and then put whole text (with replaced urls) into another div.
Let's show it on example:
User will write sentence:
"This is my site http://www.try.org/see.html and I would like to replace it"... -
^^ as Timo said. It works fine with mozilla browsers.
But then, you are using IE like event handling (working with window.event object) in your function. Mozilla is sending event object as parameter to even handler function (so alter your code). Yes, it's sad that you have to write different code for different browsers.
Example for cross-browser event handling:
[CODE=javascript]if (document.addEv entListener){...Leave a comment:
-
Maybe because the recursion is not written right. You got two cycles for the elements on the same level (for & while). Just remove one of them (i removed "for") :D not sure if that caused infinity loop
[CODE=javascript]function nodeTrav(elem)
{
while(elem)
{
if(elem.nodeTyp e==1)
{
alert("parent node is:"+elem.paren tNode.nodeName+ " current node is:"+elem.nodeN ame);...Leave a comment:
-
Why are you using the image in same url for two different states? Make different images with different urls, and just change <IMG> src based on current state of wifi. (this way you can call some page that will tell you what is the current state of wifi by XMHLHttpRequest and change image).
But if it is not acceptable (you are generating some additional information into image file). You can always force browser to ask for new...Leave a comment:
-
You are using recursive calling of function, but you forgot to declare variable "i" as local variable, so of course code will mess up because all called functions in recursion share the same global "i" variable.
change it to:Code:for(i=0;i<elem.childNodes.length;i++)
always check the variable's scope in recursion!Code:for(var i=0;i<elem.childNodes.length;i++)
Leave a comment:
-
You can not use innerHTML to insert XML tags into your site, even when it is specified as xhml. innerHTML just simply cant do it right. Well, firefox fixed it some time ago, but it's just FF (it is from ver 1.5 or so). But it is not problem in your case, because you are using it just as "workaround " for XML parsing. As acoder said, use responseXML property to parse XML.
PS: One more thing about innerHTML: from my experience,...Leave a comment:
-
Code:var fElement = document.getElementsByName('elementname'); alert(fElement.length);as an examples ...Code:var newobj = document.createElement('input'); newobj.name = 'myname'; document.body.appendChild(newobj);Leave a comment:
-
And fix referencing too, because it is invalid. Make it this way:
Code:document.getElementById('LinksInternal').style.display = '';Leave a comment:
-
in htmlCode:<input type=text value="Vijay" id="txt1" readonly />
OR
[CODE=javascript]document.getEle mentById('txt1' ).setAttribute( 'readonly','tru e');[/CODE]
in javascriptLeave a comment:
-
No, it is not ... it something different.
Look at your code closely. by doPrint(); you are calling doPrint function and you are storing result of this function into document.onload . So, you are not calling doPrint function after document is loaded as you would expect (which may cause issues as you described)....Code:function doPrint(){ this.focus(); this.print(); } document.onload=doPrint();Leave a comment:
-
Why so much anger? I was not telling that IE is 100% fine or better then other borwsers. The only thing i tried to say was that it's not impossible to write quite rich pages that work in IE7 and other w3c compilant browsers today. It was hard as hell ... almost impossible with IE6, but I am running quite complicated pages in IE7 and other browsers with just minor changes (and huge work-arounds for IE6). What is so bad on such a statement, that you...Leave a comment:
-
Today, IE is not that evil. The problem is, that many programmers still work in Quirks mode that can be easily turned off from IE6. Is it browser's fault that programmers are not using what browsers provide? My all pages work in IE6,IE7,Opera 9.02+ and FF. And I have to say, that 99% of problems I am dealing with belong only to outdated IE6 (tho, still high % of usage). Whatever everyone keep saying, I dont have hard time with IE7. Really ... Just...Leave a comment:
-
replace lines 42-70 with this code:
[CODE=javascript]
var response_receiv ed = false;
function confirm_delete( )
{
if (response_recei ved) return true;
var agre=confirm('a re you sure you want to delete the data???') ;
if(!agre) return false;
confirm_use();
return false;
}
function confirm_send(us tr)
{
var http...Leave a comment:
-
Well, you are calling asynchronous ajax request, but your code is writen like request is synchronous. So your code works like that:
1) starting ajax request
2) sending form
3) getting ajax response
So, you are getting / handling response after page is submitted (is gone), so result is weird.
Try to change this function:
...Code:function confirm_delete() { var agre=confirm('areLeave a comment:
-
The sad part is, that acoder is actually right. Your arc90_sidenoteT XT class has fixed width of 12em which causes your overflow. :(...Leave a comment:
-
Exactly what acoder said. Dont forget that "QQ" + i should be the id of element - not its name. I bet your problem is right there (that you are using name instead of id), bacause in IE, getElementById returns elements not only by id, but even elements with given name (which is invalid). That's why it works in IE and not in Mozilla....Leave a comment:
-
Post it here or PM code to me as well. Really want see the reason too.
(seems like it has problems when you are sending many requests as "burst")
I got strange feeling in my stomach that I missed something simple again :)Leave a comment:
-
I did not follow the purpose of your script. But you got error (typo?). in your code. you are sending id to your function as string value. But in setTimeout you forgot to add quotation marks:
But your code will end up in infinity loop of calling start() for your item id (every 1 sec). But it's maybe because the code is not finished yet.Code:setTimeout("start('"+itemId+"'); ", (1000));Leave a comment:
-
Oh, cycle ... sure. Well, if your alert(cBox.valu e) shows values, problem is somewhere else.
Let's look at it:
- You are creating http variable locally in function.
- And you are creating handler for onreadystatecha nge event as local function as well.
So, that event handler function creates closure (because it is referenced outside in instance of XHR object). But (because of cycle) all http request objects share...Leave a comment:
No activity results to display
Show More
Leave a comment: