How can I make more effective use of Browser.ExecJS?

0 favourites
  • 1 posts
From the Asset Store
This is a single chapter from the Construct Starter Kit Collection and the Student Workbook from the Workshop.
  • Just recently I've started using tiny little bits of javascript through the Browser.ExecJS expression. It's neat, and has solved a few problems that vanilla C2 just can't. I'm learning more about javascript now (most of what I've gotten has been cribbed from other sites/this forum), but would anyone like to share any of their favourite ExecJS snippets? Here are mine

    This one gets the start and end caret position of a textbox/area with the CSS ID 'text':

    {var ctl = document.getElementById('text');
        var startPos = ctl.selectionStart;
        var endPos = ctl.selectionEnd;
        startPos + "","" + endPos;}[/code:3w47tz8o]
    
    This one imports a stylesheet.css from project files to apply to the layout:
    [code:3w47tz8o]function  myFunction(filename, filetype){
            var fileref=document.createElement('link')
            fileref.setAttribute('rel', 'stylesheet')
            fileref.setAttribute('type', 'text/css')
            fileref.setAttribute('href', filename)
            document.getElementsByTagName('head')[0].appendChild(fileref)};
     myFunction('stylesheet.css', 'css');[/code:3w47tz8o]
    
    And this one makes it so that the two textareas named 'code' and 'lines' scroll together:
    [code:3w47tz8o]$('#code').scroll(function(){$('#lines')[0].scrollTop = $('#code')[0].scrollTop;});[/code:3w47tz8o]
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)