w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Extend javascript function into dynamically loaded file
Use event delegation. If the user clicks an element, it'll 'click' all parent elements of that element too. You can use this behaviour: Instead of $('#home_button').on('click', function(){ use: $('selector for parent of that button').on('click', '#home_button', function() { ... } The problem is that on the moment you call your function, it'll bind the handler to all elements it matches at that point. If you add a new element that matches that selector, it won't have the handler attached to it (the moment you attached the handler to the elements has already passed). The trick is to attach the handler to a parent object instead (an object that doesn't get dynamically added), and only execute the function if the clicked element matches the selector string in the second argument of .o

Categories : Javascript

Adding javascript to a XML file transformed with XSLT using a Greasemonkey script
Don't use onclick. This goes triple for userscripts, as there are additional scope and/or sandbox conflicts. Also, it's a poor idea to try and add JS into the XSLT file/text, and there is no need for script injection in this case either. Use the script to do whatever JS manipulation you have in mind. For example: // ==UserScript== // @name _XML Renderer with javascript functionality // @description Stylesheet and javascript for xml results // @include http://YOUR_SERVER.COM/YOUR_PATH/*.xml // @resource xslFile Q_17998446_transform.xsl // @grant GM_getResourceText // ==/UserScript== var xsl_str = GM_getResourceText ("xslFile"); var processor = new XSLTProcessor (); var dataXSL = new DOMParser ().parseFromString (xsl_str, "text/xml"); processor.importSty

Categories : Javascript

How do I find out when a tab I've opened with greasemonkey is loaded?
I found a way around the problem... oddly enough, I couldn't do it when using GM_openInTab to create the window, but using mywin2=window.open("http://www.aywas.com/message/notices/9801049/", "my_win2"); allowed me to use the following code to detect the load and close the tab only after it was loaded enough for my purposes! (Although the 'window title' bit of that code above didn't seem to do anything...) mywin2.addEventListener('load', function() { mywin2.close() }, false);

Categories : Javascript

Replace specific table values using a Greasemonkey script
this javascript code let's you replace the content of a TD by it's index where 0 is the first element. var tbl=document.getElementsByTagName("table")[0]; //get the first TABLE var trs=tbl.getElementsByTagName('tr'); //get all TR's in that table var replaceTD=function(TRindex,TDindex,value){ trs[TRindex].getElementsByTagName('td')[TDindex].innerHTML=value; // replaced with innerText }; to change the second TD of the first TR that is not a title (so the third) your indexes will be TRindex=2 cause it starts from 0 ... and the TDindex=1 and the function you will call is : replaceTD(2,1,'WHATEVER');

Categories : Javascript

Calling externally loaded javascript functions in code
I would suggest to put the different piceces of js into different files & add them with php. But for that, first tailor the js to be independent chunks i.e one piece of js should not be accessing variables from another. So it would look something like : <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <script type="text/javascript" src="myScript.js"> </script> Contents of myScript.js <!--Load data from Wordpress into the arrays so we can use them on a map later--> locationLat[i] = "<?php echo get_post_meta( get_the_ID(), 'locationLat', true ) ?>"; locationLong[i] = "<?php echo get_post_meta( get_the_ID(), 'locationLong', true ) ?>"; postURL[i] = "<?php echo get_permalink( $id );?>"; postExcerpt[i] = "&

Categories : Javascript

How javascript function are loaded in the script tag
1.Are these functions retrieved from js files or any other mechanism? No, built-in functions are part of the language and most likely implemented in C or C++. However, since JavaScript is a dynamic language, a built in function could be re-defined somewhere by a Javascript function. For example: String.prototype.substr = function () { return 'Take that, built-in function!'; }; var s = 'Hello'; window.alert(s.substr(1,2)); 2.If yes where are they located? See answer 1. However, with open-source JavaScript engines you'd be able to dig up the source code online if you were curious about the implementation of these built in functions. For example, the source code to V8, the JavaScript engine Chrome uses, can be found here. One way to tell if a function is native would be to p

Categories : Javascript

how to run a javascript function loaded using jquery .load
use the callback function of load() method: $(pageElement).load('pages/page' + page + '.html',function(){ $('#myCanvas').on('click',function(){alert('canvas clicked');}); }); Or use delegation, e.g: $(document.body).on('click','myCanvas', function(){ alert('canvas clicked'); });

Categories : Jquery

Javascript function is not triggered for a div thats loaded with Ajax
As the div#stream is loaded with Ajax, this function $('#stream').infinitescroll is not getting Triggered. make sure you call the .infinitescroll({ after the div#stream is loaded in the document.. $.ajax({ ... success:function(){ //your codes which appends #stream $('#stream').infinitescroll({ navSelector : ".paginate:last", nextSelector : "a.paginate:last", dataType : 'json', appendCallback : false, path: "someurl" }, function(json, opts){ alert("json Fetched..") }); } }); you need to call the methods again when an element is dynamically added. calling it in document.ready will be of no help since when the document is ready the #stream div might not be present in the document when this method is called

Categories : Javascript

Run Javascript function when object content has been loaded
You should use onload/ready event of jquery - http://api.jquery.com/ready/ $('#circles').ready(function(){ changeColor(); });`

Categories : Javascript

Using a function with ternary operand as the new value parameter in Javascript replace function
Simple mistake, you forgot the return foo = foo.replace("test", function(){ return typeof bar.baz !== 'undefined'? bar.baz : "default_text"}); ^^^^^^

Categories : Javascript

Looking for Accurate Ruby, Javascript, or R Excel RATE() or IRR() Function Implementation
After some testing, I am comfortable with this implementation of IRR() in R: https://stat.ethz.ch/pipermail/r-help/2008-August/169619.html Here it is in the form of a script runnable via the Rscript command: args <- commandArgs(TRUE) periods = as.numeric(args[1]) payment = as.numeric(args[2]) value = as.numeric(args[3]) monthsInYear = 12 timeline <- (0:periods) payments <- payment + (0 * timeline) payments[1] <- value f <- function(r) sum(payments * exp(-r * timeline)) irr <- function(f) uniroot(f, c(0, 1))$root irr(f) * monthsInYear

Categories : Javascript

JavaScript file cannot be loaded and executed in Eclipse web app
Jersey only handles RESTful methods. Jersey does not handle serving other web resources. That is why http://localhost:8080/myapp/rest/send.js results in a 404 "Not Found". You will need to define another <servlet> and <servlet-mapping> in your web.xml for handling the other HTML, CSS, JavaScript, image, etc. resources. An application I work on uses the Faces Servlet for serving not only the JSF/Facelet pages but also, I think, it is the one serving the JS, CSS, etc. Then, the correct URL to load send.js will look like http://localhost:8080/myapp/send.js

Categories : Java

replacing text between two strings in javascript using greasemonkey
The easiest way to do this would be with a regular expression. var comment = "[youtube]http://www.youtube.com/embed/XGSy3_Czz8k[/youtube]", match = comment.match(/[youtube]([^[]*)[/youtube]/); if (match) { var iframe = document.createElement("iframe"); iframe.src = match[1]; document.body.appendChild(iframe); }

Categories : Javascript

How can I submit this form properly with javascript/greasemonkey?
With jQuery you could submit this form like this: In this function you can process the data of the form. $(document).on("submit", "form", function(e){ e.preventDefault(); // get the data of the form var url = $(this).attr("action"), _csrf_token = $(this).find("input name=['_csrf_token']).val(); // jquery ajax call for example $.ajax( ); });

Categories : Javascript

Can a javascript file be unloaded after loaded with Ext.Loader.loadScript?
Loader.loadScript() appends a new <script> tag to the DOM (in this case the HTML head) and then the browser runs that script. You can remove the script from the DOM, but AFAIK in most browsers, the variables/functions/objects declared in the loaded script will still be available. You could delete them. Here is a test, loading jQuery from ExtJS (I don't know why you'd want to do that ;): http://jsfiddle.net/ny49m/5/ Ext.Loader.setConfig({ enabled:true }); console.log(typeof jQuery == 'undefined'); //true Ext.onReady(function(){ Ext.Loader.loadScript({ url:'http://code.jquery.com/jquery-1.10.1.min.js', onLoad:function(){ console.log(typeof jQuery == 'undefined'); //false //remove the script tag from the DOM: var scripts = documen

Categories : Extjs

Javascript Replace Function
I don't think you want to be doing this with a regex, you should use DOM methods instead, like this HTML <div id="foo"> <a href="http://www.somesite.com" target="_blank" class="footer">Site 1</a> </div> Javascript var fooA = document.getElementById("foo").children[0]; fooA.href = "http://www.othersite.com"; fooA.title = "Other Site"; fooA.firstChild.nodeValue = "Site 2"; Result <div id="foo"> <a href="http://www.othersite.com" target="_blank" class="footer" title="Other Site">Site 2</a> </div> On jsfiddle

Categories : Javascript

Removing CSS Borders with javascript in greasemonkey/tampermonkey for facebook
border-right is a style property, not an element attribute, so removeAttribute won't work. Instead try this: document.getElementById("mainContainer").style.borderRight = "none"; (Note that border-right becomes borderRight for JavaScript, and make sure you spell names exactly.) However you might prefer user stylesheets. Browser extensions such as Stylish let you write CSS that is applied automatically, instead of going through script. (You can hide things using display: none, or mute them with opacity: 0.5.)

Categories : Javascript

Changing a div with a remote javascript file
I think you will find it is simply an ordering problem. The JavaScript is executing before the div is ready. Move the script beneath the div, like so: <div name="lev">Hallo world</div> <script type="text/javascript" src="http://pageYserverY.com/remote.php?hat=strong"></script>

Categories : Javascript

Changing file loaded from internet to file loaded from internal memory
You can provide a locally stored file the same way. With Context.getDir() or Context.getFilesDir() you create the Fileobject where you get the URL with file.toURI().

Categories : Android

in which situations we schould write the definition of the function only in the implementation file?
Header files generally store function definitions. They can also store method implementations like: inline string method() { return something; } But you have to watch your references. The most likely reason that your function would not work in the header was that you did not have a reference to the Form1.h header that you needed. In your Form2 cpp file, you include a reference to Form1.h. The problem in the case of headers is that you could quickly have a circular dependency. Form2.h requires a reference to Form1.h, but then Form1.h needs a reference to Form2.h and so on. So by putting your implementation down in the cpp area, you can provide ALL the header referencing you need without worrying about circular dependencies.

Categories : Dotnet

Javascript replace a div's content with a function when active
Found the solution <div style="display:none;" id="CartContent"> %%Panel.SideCartContents%% </div> <script> jQuery(document).ready(function(){ var itms = '%%GLOBAL_CartItems%%'; var cartHTML = jQuery("#CartContent").html(); var cartAmount = jQuery(cartHTML).find("#tot strong").html(); jQuery("#cartText").html( itms + ' - ' + cartAmount ); }); </script> <span id="cartText">Cart Empty - $0</span> Then on my shopping cart file I put this: <span id="tot">%%LNG_SideCartTotalCost%%</span> This then displayed Cart Empty - $0 until an item went in the cart then it put in the info and replaced the div contents

Categories : Javascript

Porting the Javascript replace() function to Objective C
You're in luck! NSString already has stringByReplacingOccurrencesOfString:withString:. It should work fine with new lines. Also, if you just want to strip all newlines and carriage returns, you can use: [string stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]]; NSString comes with all kinds of things, and they are all documented here.

Categories : Javascript

At the very end of my text file I need to replace a , with a ; via php code
You can simply use a substr: $text = substr($actualText, 0, -1); $text.=';'; This is assuming that the full stop is indeed the LAST character in the file/variable.

Categories : PHP

Remove and replace another onclick function in a div through Pure Javascript?
Consider a sample HTML page: <html> <head> </head> <body> <div id ="d1"> <span class="plus childNode1" onclick="expand_collapseChildnodes('childNode1')" id="abc"></span> </div> <div id ="d2"> </div> </body> </html> Now to move the element with id abc from DOM element with id d1 to another with id d2 //get the element var element = document.getElementById("abc"); //detach from source document.getElementById("d1").removeChild(element); //remove onclick attribute element.removeAttribute("onclick"); //add the modified attribute element.setAttribute("onclick", "sampleFunc()"); //attach the element to another source document.getElementById("d2").appenChild(eleme

Categories : Javascript

Greasemonkey script does not load external JS and CSS file
That linked answer was from 2011, and Greasemonkey has changed a lot since then. (Note, I just now updated that answer to reflect the changes.) Basically, you need to use @grant directives now. If you looked on Firefox's error console (CtrlShiftJ), you might have seen error messages like: GM_addStyle is not defined Here is a bare-bones addition of jQuery-UI to demonstrate the process: // ==UserScript== // @name _YOUR_SCRIPT_NAME // @include http://YOUR_SERVER.COM/YOUR_PATH/* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js // @require http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js // @resource jqUI_CSS http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css // @grant GM_addStyle // @grant GM_getResou

Categories : Javascript

How to transform an XML file with XSLT, using a Greasemonkey script?
I would have added this in a comment, but I don't have the relevant reputation. There are two things that I would check. Especially if this is working on a string, and not a file from the server like you said Make sure that what you are getting from the server is a string, and not an object Make sure the xml you are getting from the server is correct. If you aren't getting a string, you can do an ajax request to get the text from the xml. And then load that as your new xml var. And if you really just wanted to make your xml user friendly, I would suggest checking out http://code.google.com/p/vkbeautify and http://google-code-prettify.googlecode.com/svn/trunk/README.html Those should maintain the xml format while stylizing it to make it easy to read. Plus, you won't have to mess with

Categories : Javascript

Twig (Symfony2) - replace function - replacing from variables - is it possible? (part completed code)
When you use '{{ a }}{{ b }}', it is nothing but a simple string to twig: {{ '{{ a }}{{ b }}' }} would just output: {{ a }}{{ b }} Then, if you want to use expression as keys in twig, you need to put them in parentheses: {% set name = 'Adrien' %} {% set hash = {(name): 'hello', name: 'hi'} %} {% for key, value in hash %} {{ key }} => {{ value }} {% endfor %} would output: Adrien => hello name => hi So you fixed solution is: {% set a %}abc{% endset %} {% set b %}123{% endset %} {{ "test_abc123_xyz"|replace({ (a ~ b): '' }) }} The ~ is the concatenation operator in twig.

Categories : Symfony2

In what Javascript engines does Function.prototype.toString not return the source code of that function?
What current Javascript engines don't behave this way? Your question isn't really well-defined, given that you haven't defined "popular". Is IE6 popular? IE5? IE4? Netscape Navigator? Lynx? The only way to properly answer your question is to enumerate which browsers you wish to support and check them. Unfortunately kangax's table http://kangax.github.io/es5-compat-table/# doesn't test Function.prototype.toString Chrome's console will even tell you (when you pass anything other than a function o Function.toString.call), that Function.prototype.toString is not generic mandated in the spec the spec refrains from making any commitment as to what the behaviour should be when applied to functions The required behavior is specified in ECMA-262 version 1 (from 1997, http://

Categories : Javascript

package code.google.com/p/go.example/hello: exec: "hg": executable file not found in %PATH%. How to get remote golang packages?
The package you are trying to install is under the Mercurial (hg) source control system. You need to install Mercurial to be able to clone the package. http://mercurial.selenic.com/

Categories : Go

"remote: true" does nothing on content that has been loaded dynamically
You shouldn't need to do anything. rails js doesn't "parse" the document when is loaded, rather, it binds the events to the document. So if you create new element and trigger an event, it'll bubble up and work anyway (like the deprecated .live() method in jQuery). You can see this in action in line 290 of the rails js script $(document).delegate(rails.linkClickSelector, 'click.rails', function(e) { As long as you define your callbacks correctly (like ajax:success, ajax:complete, etc) everything should be dandy. For more info take a look at: Github of the script Site with info about remote links jQuery .delegate() ( which is deprecated in favor of .on() )

Categories : Ruby On Rails

Server Code HTTp POST to remote server; Javascript API call
use the $ajax() function from jquery use urllib and urllib2 to access external resources from python. Call these libraries from within your view function Here's an example for the $ajax function: $.ajax({ type: "GET", url: '/htmlApi/sendSms/', data: { 'phone':'+12412354135', }, success: function(data){ $("#ajaxDestination").html(data); } }); here's an example of a view function that posts data to the remote server: def verify1(request): u = request.session['user'] u.phone_number = request.GET['phone'] u.save() apiUrl = "http://www.XXXXXXXXX.net/api/send.aspx?username=XXXXXXX&password=XXXXXX&language=1&sender=XXXXXX&mobile=" + request.GET['phone'] + "&message=" + 'ghis' + " is your verificatio

Categories : Javascript

is it possible to replace a javascript file in the network or sources tab of chrome
You can edit the existing JavaScript code. Not sure how to replace the JavaScript file. Press F12 it bring the developer tools at bottom of your page . Go to resource and select your JavaScript file It will open inside editor(right side) there you can modify your script.

Categories : Mongodb

How does client know the EJB bean implementation is remote or local in ejb3
There are two different interfaces available when you are writing an EJB. One is remote and one is Local. Remote, as it name suggests is for remote client that want to remotely call (or fire) functions and get some results. On the other hand Local is designed to be used in a local environment, for example in a case if another EJB or even a POJO in your system is using that. The usage would be the same as when you want to use an EJB using its Remote interface. However, it has less headache for the server to handle that. That's the only reason you might want to use a Local interface instead of Remote interface. Local interface is not local to JVM but local like an other POJO class. Local client view cannot be accessed: When an EJB or web component is packaged in a different application's E

Categories : Java

How to replace quotes in code for Reading Text File to CSV without causing character truncation?
You did not write the first letter of the line. I also merged your replacing of carriage return and line feed into one replacing of Environment.NewLine. You should also flush the writer before closing or set the writer.Autoflush property to true. Here is my optimized code: static void TxtToCSV(string s, TextWriter writer) { foreach (var line in s.Replace(", ", "").Split(new string[] { Environment.NewLine }, StringSplitOptions.None)) { foreach (var t in line) { writer.Write(t); } writer.WriteLine(); } writer.Flush(); }

Categories : C#

How can I replace config file database links in one place in source code? (asp.net/razor)
The database connection string(s) can be set up centrally in 1 place, in the Global.asax.cs file, as part of the Application State, and then referenced from anywhere else in the project. Step-1: Define the connection string(s) as static variables in Global.asax.cs: namespace TestProject { // Note: For instructions on enabling IIS6 or IIS7 classic mode, // visit http://go.microsoft.com/?LinkId=9394801 public class MvcApplication : System.Web.HttpApplication { public static string ConnectionString1; public static string ConnectionString2; protected void Application_Start() { #region Build application state for the app-specific items needed by us ConnectionString1 = "Server=yourserver;Database=yourdb;etc etc";

Categories : Asp Net Mvc

How is data loaded from a remote database stored locally (in memory)
While it's very easy the put the fetched data right into your array and use it from there, it is likely that you would be benefitted by using a local database for two main reasons: scalability and persistance. If you are hoping to download and display a large amount of data, it may be unsafe to try to store it in memory all at once. It would be more scalable to download whatever data you need, store it in a local database, and then fetch only the relevant objects you need to display. If you download the data and only store it in an array, that data will have to be re-fetched from the remote database and re-parsed on next load of your app/view controller/etc before anything can be displayed. Instead, create a local database in which to store the downloaded data, allowing it to be readily

Categories : IOS

JavaScript: Not calling javascript function from the code behind
do something like this.. I have not tested the code...... In the child window <body onunload="refreshParent();"> function refreshParent() { window.opener.location.href = window.opener.location.href; if (window.opener.progressWindow) { window.opener.progressWindow.close() } window.close(); } close the child window when you have the session variable...(i dont know asp so cant help you with that syntax)

Categories : Javascript

How to call javascript function from asp.net code behind function
As far as i know you can't do that.You can run javascript code before page load or after the server side code has been executed.You can't make javascript work in between c# code execution and then return back to c#.

Categories : Javascript

How to load some data into $rootScope from remote server before the module's controller is loaded?
The $http service is implemented using promises. The code you write in your success handler will run when the promise is resolved. Due to the asynchronous nature of promises, it is unknown when this happens. It can be 1 second later or 10 seconds later. Meanwhile, your other code continues to run and your controller is probably getting loaded before the promise is resolved. The best way to tackle this problem is to think in 'asynchronous' terms, not force some kind of synchronous behavior. Here are a few valid options: You could move the code to your controller and move your logic to the success handler like this: myModule.controller('SomeCtrl', function($rootScope, $http, $location) { $http.get("http://mydomain/load_user/"). success(function(respData) { // Perform any l

Categories : Angularjs

JQuery Replace "Special" Function (like replace(/#[^#]*$/, "") replace(/?[^?]*$/, ""))
They are called regular expressions. Regular expressions are patterns used to match character combinations in strings

Categories : Jquery



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.