Posts

Showing posts from April, 2016

Modify the URL without reloading the page

This can now be done in Chrome, Safari, FF4+, and IE10pp4+! Example: function processAjaxData ( response , urlPath ){ document . getElementById ( "content" ). innerHTML = response . html ; document . title = response . pageTitle ; window . history . pushState ({ "html" : response . html , "pageTitle" : response . pageTitle }, "" , urlPath ); } You can then use  window.onpopstate  to detect the back/forward button navigation: window . onpopstate = function ( e ){ if ( e . state ){ document . getElementById ( "content" ). innerHTML = e . state . html ; document . title = e . state . pageTitle ; } };

how to get current URL in jQuery/JavaScript?

To get the path, you can use: var pathname = window . location . pathname ; // Returns path only var url = window . location . href ; // Returns full URL

How to include a JavaScript file in another JavaScript file?

The  jQuery  library provides loading functionality  in one line : $ . getScript ( "my_lovely_script.js" , function (){ alert ( "Script loaded but not necessarily executed." ); });

if element is hidden checking by jQuery

// Checks for display:[none|block], ignores visible:[true|false] $ ( element ). is ( ":visible" );

Page redirect using jQuery

jQuery is not necessary, and   window.location.replace(...)   will best simulate an HTTP redirect. It is better than using  window.location.href = , because  replace()  does not keep the originating page in the session history, meaning the user won't get stuck in a never-ending back-button fiasco. If you want to simulate someone clicking on a link, use  location.href . If you want to simulate an HTTP redirect, use  location.replace . Example: // similar behavior as an HTTP redirect window . location . replace ( "http://domain.com" ); // similar behavior as clicking on a link window . location . href = "http:// domain .com" ;

Edit an incorrect commit message in Git

Amending the most recent commit message git commit -- amend Will open your editor, allowing you to change the commit message of the most recent commit. Additionally, you can set the commit message directly in the command line with: git commit -- amend - m "New commit message" …however, this can make multi-line commit messages or small corrections more cumbersome to enter. Make sure you don't have any working copy changes  staged  before doing this or they will get committed too. ( Unstaged  changes will not get committed.) Changing the message of a commit that you've already pushed to your remote branch If you've already pushed your commit up to your remote branch, then you'll need to force push the commit with git push < remote > < branch > -- force # Or git push < remote > < branch > - f Warning: force-pushing will overwrite the remote branch with the state of your local one . If there are commits on the remote b

How do you undo the last commit?

down vote accepted Undo a commit and redo $ git commit -m "Something misspelled" (1) $ git reset --soft HEAD~ (2) << edit files as necessary >> (3) $ git add ... (4) $ git commit -c ORIG_HEAD (5) This is what you want to undo This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message 1 , or both. Leaves working tree as it was before  git commit . Make corrections to working tree files. git add  whatever changes you want to include in your new commit. Commit the changes, reusing the old commit message.  reset  copied the old head to  .git/ORIG_HEAD ;  commit  with  -c ORIG_HEAD  will open an editor, which initially contains the log message from the old commit and allows you to edit it. If you do not need to edit the message, y