Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSfiddle : how to create multi-JS/CSS/HTML files project?

Is there a way to create a serious HTML/CSS/JS project with multiple HTML, CSS, JS files on JSfiddle.net ? If yes, how to do it ?


I want to create a basic mobile apps based on HTML/CSS/JS, about a dozen of HTML/CSS/JS files. I would like to develop it all on JSfiddle, my favorite Online JavaScript IDE. But JSfiddle.net while a clean way to test projects stays limited to:

  • 1 html file (personal)
  • 1 CSS file (personal)
  • 1 JS file (personal)
  • several external resources (CSS, JS libs, data) which request you another webhosting.

The official doc suggesting Github hosting for 1HTML/1JS/1CSS/someDataFiles is not satisfying. I wish all on JSFiddle, and more files in my project.

like image 323
Hugolpz Avatar asked Mar 22 '13 14:03

Hugolpz


People also ask

How do I run HTML CSS and JavaScript files together?

To link a CSS file with your HTML file, you have to write the next script on your HTML file inside the head tag. To link a Js file with your HTML, you only have to add the source of the script inside the body tag or outside; it doesn't matter.

What is better than jsFiddle?

There are more than 50 alternatives to jsFiddle, not only websites but also apps for a variety of platforms, including Android, Self-Hosted solutions, Windows and Linux. The best alternative is CodePen, which is free. Other great sites and apps similar to jsFiddle are Pastebin.com, Replit, CodeSandbox and JS Bin.

How do I run a JavaScript project in HTML?

To execute JavaScript in a browser you have two options — either put it inside a script element anywhere inside an HTML document, or put it inside an external JavaScript file (with a . js extension) and then reference that file inside the HTML document using an empty script element with a src attribute.

How do I run JavaScript in jsFiddle?

Entering and running code JSFiddle has the notion of panels (or tabs if you switch into the tabbed layout), there are 4 panels, 3 where you can enter code, and 1 to see the result. Once you enter code, just hit Run in the top actions bar, and the fourth panel with results will appear.


1 Answers

You can do it inside a jsFiddle but there are few limitations, and you are probably not going to be satisfied with it.

  1. You can test only 1 HTML multiple pages template. But in case of jQuery Mobile framework this will be enough, as you can place numerous jQM pages inside a 1 html file.

    For example, this is my jsFiddle template when helping to this group: http://jsfiddle.net/Gajotres/yWTG2/

  2. You cant use normal form submitting. Instead you should use ajax to sumbit form data.

    In my other answer you can find solutions for ajax form submitting and how to send parameters during the page transition: jQuery Mobile: Sending data from one page to the another

    In case you want to communicate with an remote host:

    var ajax = {
        sendRequest:function(save_data){
            $.ajax({url: 'http://localhost/JSONP_Tutorial/json.php',
                data: save_data,
                async: true,
                beforeSend: function() {
                    // This callback function will trigger before data is sent
                    $.mobile.showPageLoadingMsg(true); // This will show ajax spinner
                },
                complete: function() {
                    // This callback function will trigger on data sent/received complete
                    $.mobile.hidePageLoadingMsg(); // This will hide ajax spinner
                },
                success: function (result) {
                    if(result == "true") {
                        $.mobile.changePage( "#index", { transition: "slide"} ); // In case result is true change page to Index
                    } else {
                        alert('Login unsuccessful, please try again!'); // In case result is false throw an error
                    }
                    // This callback function will trigger on successful action
                },
                error: function (request,error) {
                    // This callback function will trigger on unsuccessful action                
                    alert('Network error has occurred please try again!');
                }
            });
        }
    }
    
  3. jsFiddle has a stupid policy where they want to prevent usage of full HTML files. They are trying to enforce this with stupid error warnings in HTML content part. You will need to have something like firebug plugin for Firefox or Chrome to remove this stupidity. Or you can even do it with Grease Monkey plugin.

  4. In case you want to use full HTML template like in this example: http://jsfiddle.net/Gajotres/yWTG2/ you will need to use your javascript code in onDomready state.

  5. Some functionalities are not going to work. Like window.orientationchange event.

like image 177
Gajotres Avatar answered Oct 13 '22 11:10

Gajotres