NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page [javascript] Error in google chrome

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Reply
 
LinkBack Thread Tools
Old 07-09-2009, 06:59 AM THREAD STARTER               #1 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




[javascript] Error in google chrome


Basically my bbcode insertion javascript works near on perfect in all browsers now apart from chrome. It seems to repeat whatever is before it when you enter text:

Code:
// add simple text
function addText(Text)
{
	var obj = document.form.message;
	obj.focus();
 
	if (document.selection && document.selection.createRange)  // Internet Explorer
	{
		sel = document.selection.createRange();
		if (sel.parentElement() == obj)  
		{
			sel.text = Text;
		}
	}

	else if(typeof(obj) != 'undefined')  // Firefox
	{
		var longueur = parseInt(obj.textLength);
		var selStart = obj.selectionStart;
		var selEnd = obj.selectionEnd;

		obj.value = obj.value.substring(0,selStart) + Text + obj.value.substring(selEnd,longueur);
	}
 
	else 
	{
		obj.value += Text;
	}

	obj.focus();
}

// wrap code in tags or just simply add them by themselves
function addTags(Tag, fTag)
{
	var obj = document.form.message;
	obj.focus();

	// Internet Explorer
	if (document.selection && document.selection.createRange) 
	{
		sel = document.selection.createRange();
		if (sel.parentElement() == obj)
		{
			sel.text = Tag + sel.text + fTag;
		}
	}

	// Firefox
	else if(typeof(obj) != 'undefined')
	{
		var longueur = parseInt(obj.textLength);
		var selStart = obj.selectionStart;
		var selEnd = obj.selectionEnd;

		obj.value = obj.value.substring(0,selStart) + Tag + obj.value.substring(selStart,selEnd) + fTag + obj.value.substring(selEnd,longueur);
	}
 
	else
	{	
		obj.value += Tag + fTag;
	}

	obj.focus();
}
You can test here:
????: NamePros.com http://www.namepros.com/programming/595360-javascript-error-in-google-chrome.html
Prxa.info Message Board >> Add New Topic

In chrome it will delete whatever was before it when entering the bbcode into the box and repeat stuff, test above to see what i mean
liam_d is offline   Reply With Quote
Old 07-09-2009, 09:50 AM   #2 (permalink)
Programming Genius

 
djdeth's Avatar
Join Date: Aug 2003
Location: Las Vegas
Posts: 949
djdeth is a name known to alldjdeth is a name known to alldjdeth is a name known to alldjdeth is a name known to alldjdeth is a name known to alldjdeth is a name known to all
 



Baby Health Adoption Protect Our Planet Animal Cruelty
I am not really sure what the fix would be. I use jQuery which will work across all browsers. Doing it from scratch can be a pain since all of the browsers render javascript differently.
djdeth is offline   Reply With Quote
Old 07-10-2009, 06:09 AM THREAD STARTER               #3 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




JQuery is way too big for what i need it for, besides this works fine in every browser apart from chrome
liam_d is offline   Reply With Quote
Old 07-10-2009, 09:14 AM   #4 (permalink)
NamePros Member
Join Date: Sep 2006
Posts: 99
Bruce_KD will become famous soon enoughBruce_KD will become famous soon enough
 



Chrome has an awesome debugging console. The line throwing out problems is:
Code:
var longueur = parseInt(obj.textLength);
Fortunately, there is an easy fix!
Just use:
Code:
var longueur = parseInt(obj.value.length);
That's tested in Chrome but not Firefox. You should be fine though, obj.value will always return the text and .length will return the length of a string.
????: NamePros.com http://www.namepros.com/showthread.php?t=595360


Bruce
Bruce_KD is offline   Reply With Quote
Old 07-10-2009, 09:25 AM THREAD STARTER               #5 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




Excellent, didn't know Chrome has that, works like a charm across all major browsers now, thanks!
liam_d is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Huge Geo Sale! Country, Cities and more! New-England, FrenchGuiana, Nordanstig.com... thevirtual Domains For Sale - Make Offer 15 01-31-2008 11:09 AM
~ LowCostMeal.com only $7 ~ (Google indexed!!) JasMate Domains For Sale - Fixed Price 0 09-06-2006 11:39 PM
google ranking (Tips) lilgee Search Engines 8 10-20-2005 03:04 PM
Premium Domain Clearance Tax Sale $10+ clemzonguy Domains For Sale - Fixed Price 2 04-11-2005 04:30 PM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 11:41 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger