In: JavaScript
17 Feb 2011Tweet When making a multilingual application programmers usually find themselves in a bit of a problem when having need to translate things in JavaScript as those JavaScript files are usually separated from PHP so they can’t call translate function for this purpose. To solve this problem I have created JavaScript translate class, so please check [...]
In: JavaScript
15 Oct 2010Tweet In order to make JavaScript countdown I made this simple JavaScript countdown snippet you could use on your website. All you need to do is count number of seconds between current time and the moment in which something will happen. Below example is the snippet you could use. LA So, there are two parts [...]
In: JavaScript
23 Sep 2010Tweet It could be useful to get current page URL and current page title. Especially if we want to make sharing plugin for our website. Often, we need that information in order to pass them as a parameter to sharing services like Twitter, Delicious, Facebook, etc… So, in order to get these information, you can [...]
In: JavaScript
20 Aug 2010Tweet Prevent iframe breakout with simple onbeforeunload function. Define function on this event in order to prevent script inside of an iframe leaving it. This code asks user if he want’s to navigate away from your page. It is not the most elegant solution, but it is the one to prevent other script from iframe [...]
In: JavaScript
20 Aug 2010Tweet Sometimes, you don’t want your website to be displayed on other websites inside of an iframe. It is easy to protect your website from being displayed inside of iframe by using following JavaScript iframe breakout snippet: 1 2 3 4 5 6 7 8 <script> function get_out_of_iframe() { if (top.location.href != self.location.href) top.location.href = [...]
In: JavaScript
10 Aug 2010Tweet To use JavaScript to open link in new tab (or window), just use following code. The right way would be to write it with handler on click event, but this way snippet is easier to read. <a href="http://example.com" onclick="window.open(‘example.com’, ‘_blank’); return false;"> JavaScript open in new tab </a> That’s all.
In: JavaScript
4 Aug 2010Tweet When you want to put a link onto a webpage and you want to run a jQuery function on that link, you probably want to attach listener to onclick event. To do that, simply copy following snippet: 1 2 3 4 5 6 7 <a href="javascript:void(0);" id="my-jquery-href">Don’t click jQuery href</a> <script> jQuery(‘#my-jquery-href’).click(function() { [...]
In: JavaScript
2 Aug 2010Tweet It is useful to focus on input field after page is loaded when user is presented with login form. Once page is loaded we shall set focus on input field so user would not need to use mouse in order to focus on it. 1 2 3 4 5 6 7 8 <input type="text" [...]
In: JavaScript|PHP
6 Jul 2010Tweet In order to lower down number of http requests and speed up your website, you can use regular JS include, to include PHP file. <link rel="javascript" type="text/javascript" href="alljs.php"> PHP JS include file This is how PHP file, that includes all JS files you want to be included, should look on your server: 1 2 [...]