Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use local javascript files to test on live site using firebug (or Chrome)?

I've got some custom JS that i'm looking to deploy on a live site, but I want to test it out first.

I'm a third-party consultant to the target site managers, and am not part of their build process, so I can't deploy in their test environments. Since it's a DOM traversal library, it's pretty specific.

I was wondering if anyone knew how to get my local javascript files to auto-insert for a particular domain or host.

Thanks!

like image 764
patrickgamer Avatar asked Aug 10 '11 16:08

patrickgamer


People also ask

How do I test locally in JavaScript?

Or you can try CTRL + SHIFT + I which will open the tools in Chrome and Firefox. Within your browser's developer tools there is a tab called the Console. You can use this to run small snippets of JavaScript code.

How do I run a .JS file in my browser?

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 see all the JavaScript files on a website?

You can also press Ctrl + Shift + C on your keyboard to open the developer tools. In the top-left section of the developer tools, make sure Elements (A) is selected at the top. In the condensed code under the Elements header, find the <script> tag containing a link to a . js file (B).


2 Answers

Why not just inject the script you're working on in firebug's console:

var script = document.createElement('script');
script.src = 'url to local file';
document.appendChild(script);

Or if you have jQuery

$.getScript('url to script file.js');
like image 147
qwertymk Avatar answered Sep 27 '22 16:09

qwertymk


Install Greasemonkey Add-On for Firefox.

This Add-On can inject Javascript for pages with certain URLs matching a regex given in the injected JS-file.

If you want to learn how others are writing their Greasemonkey-Scripts then search for FF Add-Ons that start with "BetterXYZ" like BetterGmail, BetterFacebook, BetterGoogle ... Greasemonkey-Skripts are in fact Javascript-Files with special initial JS-Comment and a special file extension "*.user.js".

like image 33
Fabian Barney Avatar answered Sep 27 '22 16:09

Fabian Barney