Posts

Showing posts with the label Javascript

Ruby on Rails enable history in ajax calls

Refer below link http://lindsaar.net/2008/2/21/history-buttons-with-ajax-and-ruby-on-rails and use the code window.dhtmlHistory.create({ toJSON: function(o) { return JSON.stringify(o); } , fromJSON: function(s) { return JSON.parse(s); } }); instead of window .dhtmlHistory.create({ toJSON: function (o) { return Object .toJSON(o); }, fromJSON: function (s) { return s.evalJSON(); } }); on that post Happy learning

close current browser tab

I used the script <script type = "text/javascript"> function closeWindow(){ window.open('','_self',''); window.close(); } </script> this works well with IE (it overrides prompt) and chrome but is not working with Firefox as by default Firefox don't allow to close tab using JavaScript It is needed to follow these steps in Firefox 1. Go to address bar and type about:config 2. Go to parameter dom.allow_scripts_to_close_windows 3. Set its value as true

Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable) Error in Rails 3.1.0 rails s

Installing node.js fixed this for me go to https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager or run the following commands on your terminal sudo apt-get install python-software-properties sudo add-apt-repository ppa:chris-lea/node.js sudo apt-get update sudo apt-get install nodejs

Send ajax request from jquery.

It is better to send Ajax requests directly from java script or jquery instead clicking on button from Java Script to send Ajax request. insecure https protocol IE shows some error if you send clicking on button from java script to send Ajax request Sample code:- $j.ajax({  type: "POST",   url: " https://myurl.com/recent "  data: "requstids="+response.request_ids   })

Jquery AJAX not working with session It is not taking old session issue with solution .

In my rails application when I trigger a Ajax request with my javascript in below way $j.ajax({ type: "POST", url:" https://mydomain.com/requests ", data: "requstids="+response.request_ids }).done(function( msg ) { alert( "Data Saved: " + msg ); }); The request is firing correctly but it is not taking my old session values of user It is showing error that your session variable is not available in my log any idea why it is not taking previous session ? and how to fix that ? I got solution we need to add below code in your header javascript, which tells use browser cookie in server externally ############################################### $(document).ajaxSend(function(e, xhr, options) { var token = $("meta[name='csrf-token']").attr("content"); xhr.setRequestHeader("X-CSRF-Token", token); }); ################################################ normally by default xhr willnot sent session...

how to stop marquee on mouse over

maqquee stop < marquee onmouseover= "this.setAttribute('scrollamount', 0, 0);" onmouseout= "this.setAttribute('scrollamount', 6, 0);" > my text here </ marquee >

How to use rails.js and prototype.js librarys

The problem I wanted to use some interface element in Rails that requires prototype.js so I had to have both librairies. The problem is that there's a conflict between them. Prototype.js doesn't seem to give a damn about it but jQuery is nicer with you. It offers a noConflict method. With Rails , prototype.js is the default librairie so to override this, you could do <%= javascript_include_tag "prototype", "jquery" %> <script>$j = jQuery.noConflict();</script> This way, you will have to use $j instead of $ to call jQuery. $ would still call prototype. Another thing you could do is to use jQuery on Rails and don't give a damn about scriptaculous. I personally prefer to use librairies that are fully tested instead of using a "by-pass" that could break my code. It's your choice… --                                                                                    G SubbaRao                               ...

javascript regular expressions

Image
Introductory Guide to regular expressions Credits: This tutorial is written by Karen Gayda. Modified by JavaScriptKit.com for structure and added additional content/ examples. Please see footnote for more information on author. Introduction Validating user input is the bane of every software developer’s existence. When you are developing cross- browser web applications (IE4+ and NS4+) this task becomes even less enjoyable due to the lack of useful intrinsic validation functions in JavaScript. Fortunately, JavaScript 1.2+ has incorporated regular expressions. In this article I will present a brief tutorial on the basics of regular expressions and then give some examples of how they can be used to simplify data validation. Regular Expressions and Patterns Regular expressions are very powerful tools for performing pattern matches. PERL programmers and UNIX shell programmers have enjoyed the benefits of regular expressions for years. Once you master the pattern langua...

javascript history methods usage

The JavaScript History object - property of the window object - contains an array / list of previously visited URLs. In this article, we will look at the history object properties and methods , length , current , next , previous properties, back() , forward() and go() methods along with syntax and examples. Mostly, JavaScript history object is used to simulate the browser's back button : <a href="javascript:history.go(-1)">Go back</a> window.history window.history property has the return value as an array which contains items with details of the URL's visited within that browser window/tab. The JavaScript history object is a JavaScript object and not a DOM object. The JavaScript runtime engine automatically creates this object. window.history Properties history.length The length property of the history object returns the number of elements in the history list. General syntax of length property of history Object: history.lengt...