How do I indent my code with the tab-space key? - javascript

For example, how can I type JS some code that looks like this into the Firefox console:
if (10 > 5) {
alert("Hello world!");
alert("How are you doing today?");
alert("I'm doing great, thanks!")
}
Without resorting to using the space bar or my operating system's clipboard?
I'd like to be able to use the tab key to indent my code in the Firefox console. Whenever I press tab, Firefox goes through all the elements of the browser and web page without indenting my code.
I'm using the console provided by the Ctrl+Shift+K shortcut.

You could use the Scratchpad. It is better-designed for multi-line code editing, and supports using the tab character to indent code.
You can find it under the Developer Tools menu. Tools > Web Developer > Scratchpad on OS X, and Menu > Developer > Scratchpad on other platforms.
You can also add it to the Toolbox under Toolbox Options (the settings gear), and checking the Scratchpad checkbox.

Can try Shift + Tab (not sure if that will work on firefox, but it works in Chrome)
This probably wont answer your question either but it might....
Editor Preferences
Preferences for the CodeMirror source editor, which is included in Firefox and used by several developer tools, including Scratchpad and the Style Editor.
Detect indentation: auto-indent new lines based on the current indentation
Autoclose brackets
Indent using spaces
Tab size
Keybindings: choose the default CodeMirror keybindings, or keybindings from one of several popular editors:
Vim
Emacs
Sublime Text
https://developer.mozilla.org/en-US/docs/Tools/Tools_Toolbox

Just indent. Control + I. Hahahahaha

Related

breakpoint on javascript in CSHTML?

I have a .CSHTML file that has a javascript tag.
Within this script tag I have a few lines of javascript.
The first line of javascript refers to a property in the #ViewBag.
All other javascript lines are plain script without any MVC related references.
Observation:
I can place breakpoints (visual studio 2015) on each of these javascript lines.
However, all breakpoints has white dot in the center of the breakpoint symbol (red circle) EXCEPT for the line with the #ViewBag reference (this particular line does not have a white dot in the center).
It seems only the breakpoint without the white dot is hit during run-time.
Question:
Can somebody explain what is going on here?
What does the white dot mean?
Why is the plain red breakpoint line the only line that is hitting the breakpoint?
The Visual Studio debugger is actually expecting you to debug the actual server-side code within your .cshtml file as opposed to the client-side Javascript within it.
IIRC, Visual Studio will allow you to debug Javascript code as expected in Internet Explorer (and possibly Edge), but for other browsers you will likely want to use either a third-party tool or the Developer Tools (F12) within your browser.
An easy approach would be to take advantage of Javascript's debugger keyword, which you can place in your code and run with the Developer Tools open (just press F12 and then refresh your page). It will hit a breakpoint and the browser will allow you to step through your code as you might expect :
function doWork(){
// Ensure that this line is hit with the Developer Tools open in your
// browser
debugger;
// Do work here
}

How do I search for javascript in the firefox debugger?

Very simply, what is the equivalent in firefox to chromes "search" tab within the browser console? Specifically firefox developer edition.
Use Debugger -> Search scripts (Ctrl-P). There are multiple options in that dialog to search the current file, or all files. It searches HTML and CSS as well.

how to use the browser default view-source code highlighter

can I use the html code highlighter from the browser to my website HTML code color "Inspect element" window code color without any plugins like codemirror?
Yes: all browsers have some kind of inbuilt developers tools that let you inspect a website's HTML, CSS and other components. The shortcut and method for activating them is different for each, but all of them have a 'highlighter' that allows you to click an element on the page in order to inspect it.
Read more here on using developer tools in all broswers -> http://devtoolsecrets.com/
Chrome's developer tools are arguably the most widely known, commonly used and most powerful. Shortcut is SHIFT + CTRL + J.
edit: in light of the comments below, it looks like OP is after a specific feature of Codemirror that lets you highlight syntax. This is not possible natively in browser.

How to debug the javascript in asp.net?

I want to know ,how to debug javascript in asp.net?Can I apply break point to javascipt?
You could do following
Use debugger keyword with .Net IDE. In your javascript on your page.
something like this.
Use F12 Developer tool with IE browser.
Use FireBug with Firefox.
Use Control - Shift - J to open Developer Tools and bring focus to the Console. for Google Chrome.
If you are using Visual Studio along with Internet explorer, you can debug javascript by simply applying breakpoints. Or else if you want to debug your javascript file in fire fox or chrome browsers you can make use of tools like Firebug # http://getfirebug.com/
You can use firefox firebug or chrome tool.
for example:
you click in chrome examine the element and then in "Source" you select your script add breakpoints and debug it.
You can use Firefox but Firebug should be installed. Then, from Script tab, you should "Reload" to see all resources. After that, when you want to debug any line, put breakpoint to left side of code and when you reload the page debug will start and you can step into/ over / out, continue, rerun..
You can use Firebug tool in Mozilla browser it will notify all the error in your javascript, what java scripts are loaded, function call to javascripts are correct or not on run time.

Create a Bookmark link that works in Safari

I have tried using JavaScript "AddFavorite" function in my code, but it does not work in Safari. It works in IE, I think I remember Firefox, but nothing I have tried seems to work in Safari. All I want to do is have a link on my website that people can click on and it automatically creates a bookmark in their bookmarks folder/bookmark bar.
Does this entail Applescript or something like it? Or a deeper programming language I am unaware of?
<a href="javascript:bookmarksite('Name', 'website.com')">
From the apple forums: forum-link
On the Mac side at least, Safari does not allow a website to add a
bookmark. I'm pretty sure the same behaviour is in the Windows version
as well.
I've been down this road, and what I discovered was that Safari does NOT allow bookmarks to be made with JavaScript:
Apple Forum
bytes forum
They consider it unsafe. As frustrating as this is, I get their point.
Unfortunately, most things like this tend to be browser-specific, and picky.
my JS is about level 0, but i did find this on an old article here:
One specifically for Chrome:
Add to favourites link for Google Chrome
And another on a cross-browser bookmark link:
Cross-browser bookmark/add to favorites javascript
Hope between the previous comment and these links, you get what you needed.
Chrome and Safari does not allow it for clear security reason.
You could usee a script like this:
http://www.dynamicsitesolutions.com/javascript/add-bookmark-script/
which handles many browser and has a nice fallback: show a browser customized alert with instructuion message.
Es: in chrome it says: "Ctrl+D to add as bookmark"
In IE something similar to the following would work: (MSDN)
window.external.AddFavorite(location.href, document.title);
However, this won't work in other browsers. In Firefox, I believe you can use
window.sidebar.addPanel(document.title, location.href, '');
to create a sidebar panel (not a real bookmark) but as far as I know Chrome and Safari do not allow Javascript to automatically create bookmarks. For those, I recommend giving the user the instructions to do it manually:
drag a link to their bookmarks
pressing Ctrl + D to add a bookmark
Clicking + or star icon in the toolbar

Categories

Resources