/    Sign up×
Community /Pin to ProfileBookmark

Javascript crashing Safari

found a script on a site that will allow me to double-click to edit a span, and I’ve modified it heavily. Even before I modded it it would randomly crash Safari, and I can’t find a fix anywhere. If someone could even clean this up, even if it doesn’t fix the problem I’d be greatful, just started working with Javascript today…

[code]
function data() {
};

data.prototype.initiate = function() {
try {
// safari, firefox (yay)
this._xh = new XMLHttpRequest();
}
catch (e)
{
// yuck! internet explorer!
var _iemodels = new Array(
‘MSXML2.XMLHTTP.5.0’,
‘MSXML2.XMLHTTP.4.0’,
‘MSXML2.XMLHTTP.3.0’,
‘MSXML2.XMLHTTP’,
‘Microsoft.XMLHTTP’
);
var success = false;

for ( var i = 0; i < _iemodels.length && !success; i++ )
{
try {
this._xh = new ActiveXObject( _iemodels[i] );

success = true;
}
catch (e)
{
// trap
}
}

if ( !success )
{
return false;
}

return true;
}
}

data.prototype.occupied = function() {
actualState = this._xh.readyState;

return ( actualState && ( actualState < 4 ) );
}

data.prototype.process = function() {
if ( this._xh.readyState == 4 && this._xh.status == 200 )
{
this.processing = true;
}
}

data.prototype.send = function( urlget, data ) {
if ( !this._xh )
{
this.initiate();
}

if ( !this.occupied() )
{
this._xh.open( “GET”, urlget, false );

this._xh.send( data );

if ( this._xh.readyState == 4 && this._xh.status == 200 )
{
return this._xh.responseText;
}

}
return false;
}

http = new data;

function _gr(reqseccion,divcont) {
nt = http.send(reqseccion,””);
document.getElementById(divcont).innerHTML = nt;
}

function change( nn, actual )
{
elem = document.getElementById( nn );
elem.innerHTML = “<input type=”text” value=”” + actual.innerHTML + “” onkeypress=”return keepEnter(this, event, ‘” + nn + “‘ )” onblur=”return keepBlur( this, ‘” + nn + “‘ )” />”;
elem.firstChild.focus();
}

var urlBase = “index.php?page=ajax&”;

function keepEnter( field, evt, idfld )
{
evt = (evt) ? evt : window.event;
if ( evt.keyCode == 13 && field.value != “” )
{
field.value = field.value.replace(“/|/”,””);
elem = document.getElementById( idfld );
nt = http.send(urlBase + elem.id + “=” + escape( field.value ), “” );
elem.innerHTML = “<span ondblclick=”change( ‘” + idfld + “‘, this );”>” + nt + “</span>”;
return false;
}
else
{
return true;
}
}

function keepBlur( field, idfld )
{
if ( field.value != “” )
{
field.value = field.value.replace( “/|/”, “” );
elem = document.getElementById( idfld );
nt = http.send(urlBase + elem.id + “=” + escape( field.value ), “” );
elem.innerHTML = “<span ondblclick=”change( ‘” + idfld + “‘, this );”></span>”;
elem.firstChild.innerHTML = nt;
return false;
}
}[/code]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Kenny_Pollock 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.28,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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