chrisdiana / webden

Open source mobile friendly code playground 📱
https://webden.dev
BSD 2-Clause "Simplified" License
149 stars 18 forks source link

TypeError: document.getElementById(...) is null #12

Closed winicius87 closed 3 months ago

winicius87 commented 3 months ago

Sometimes "TypeError: document.getElementById(...) is null" appears as an error after importing an exported file.

Can this be resolved?

Also, I added a feature to load a script saved to a server. export function importURL(event) { var request = new XMLHttpRequest(); //alert("awd"); //if(event.target.value == "lcsubsequence"){ //request.open('GET', 'https://isellemails.com/MediaLight/XEhA2/suTEbIGi76.json/raw', true);//lcsubsequence //}

request.responseType = 'blob';
request.onload = function() {
    if(this.readyState == 4 && this.status == 200){
    var reader = new FileReader();
    reader.onload = onReaderLoad;
    reader.readAsText(request.response);
        //alert(request.response); //blob

    function onReaderLoad(event){
        //alert(event.target.result); //json
        app.currentProject = JSON.parse(event.target.result);
        el.name.value = app.currentProject.name;
        el.description.value = app.currentProject.description;
        setEditorValues(app.currentProject.data);
        app.unsavedChanges = true;
        ui.toast('Project imported.', 2000);
    }

    }

};

//alert('https://isellemails.com/webden/'+event.target.value+'.json');
request.open('GET', 'https://isellemails.com/webden/'+event.target.value+'.json', true);
request.send();

}

The feature I added works on the desktop but not on my mobile browser (Android Firefox and Android Chrome). I cannot find an error associated with my feature when I debug it.

winicius87 commented 3 months ago

I updated isellemails.com/webden/ but then the XMLHttpRequest is only working on desktops. That was so strange. Can this be fixed?

The update I added allows the user to select a project. It's only working on a desktop browser and not on Android Firefox.

I commented a call to document.getElementById. I think the TypeError is not displaying anymore. We have to wait and see.

The project does not load on mobile via XMLHttpRequest.

I had to place an onchange event on the select. The onclick event on the option element does not work on all browsers.

The update I made is working.