window.addEventListener('unload', function(e)
{
MyClass.shutdown();
window.removeEventListener('unload', /* how to refer to this function? */);
}, false);
Forgive me if this is a simple problem but I can't seem to find why this code:
function create_content(c)
{
var html = "<div id='header'>"+c+"</div>";
if(c == "links")
{
var ul = "<ul><li><a href='http://www.mylink.com'>My Link 1</a></li>
<li><a href='http://www.mylink2.co.uk'>My Link 2</a></li></ul>";
html = html + ul;
}
return(html);
}
Is giving me this error in Chrome (win):
Uncaught SyntaxError: Unexpected token ILLEGAL
On the line that starts with "var ul = "
Any advice would help thanks!
My jQuery code:
$(document).ready(function() {
chrome.extension.sendRequest({get: "height"}, function(response) {
height = response.value;
});
$("#id").css("height", height+"px");
});
You don't have to be concerned about the chrome.extension.sendRequest(), basically it communicates with a background page to fetch the value for "height" from localStorage and stores the value in global variable height.
The problem lies in $("#id") not being assigned the height value. However if I were to modify it such that it is now:
$(document).click(function() {
$("#id").css("height", height+"px");
});
it works. Any idea why?
Hi, i've written this peace of code:
var a=function(){
};
a.name="test";
a.prop="test2";
Now if i debug the code with the console:
console.log(a.name);
console.log(a.prop);
In Firefox i get a.name="test" and a.prop="test2", while in Safari and Chrome i get a.prop="test2" but a.name="".
It seems that there's no way to assign a "name" property on a function in Webkit browsers. Do you know why? But the most important thing is, do you know a workaround for that?
Can I use intervals in a switch statement?
Like
switch (parseInt(troops[i])) {
case <10:
editbox.style.fontSize = "13px";
break;
case <100:
editbox.style.fontSize = "12px";
break;
case <1000:
editbox.style.fontSize = "8px";
editbox.size = 3;
//editbox.style.width = "18px";
break;
default:
editbox.style.fontSize = "10px";
}
???
For the love of God I am not getting this easy code to work! It is always alerting out "null" which means that the string does not match the expression.
var pattern = "^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$";
function isEmailAddress(str) {
str = "[email protected]";
alert(str.match(pattern));
return str.match(pattern);
}
I have an 'overlay.dtd' file with a line like <!ENTITY myentity "myvalue">.
At the top of my xul file I have <!DOCTYPE overlay SYSTEM 'chrome://myaddon/locale/overlay.dtd'>.
In my xul file, I have <script src='myscript.js'>.
I want to know if there is any way to access 'myentity' from the script.
alert("&myentity;") just alerts "&myentity;"
Hi,
I am working on the new API that FB has provided. I tried using FB connect's comment system.
I did exactly what is specified in the examples(Or at least I tried to do that).
In the code i have used <fb:comments></fb:comments>
But when the page is rendered, a iframe appears where My FB page is visible. Sometimes there is nothing!
My Test Page
Can someone please suggest how can I proceed?
What I'm trying to do is to have 4 expandable divs overlapping each other with transition set in css for 0.6s. Because the expanding lasts for 0.6s I'd like to have the expanded div lose it's higher z-index after it's done collapsing, otherwise it looks silly. However, it doesn't work, the z-index remains unchanged. It's probably somethings stupid, but I just can't find it. Thanks!
<div class="wrapper" style="position: relative;">
<div id="one" style="position: absolute;" onmouseover="
this.style.height='250px';
this.style.zIndex='1';
" onmouseout="
this.style.height='50px';
setTimeout(function() {this.style.zIndex='0';},600);
">blahblahblahblah</div>
<div id="two" style="position: absolute;" onmouseover="
this.style.height='250px';
this.style.zIndex='1';
" onmouseout="
this.style.height='50px';
setTimeout(function() {this.style.zIndex='0';},600);
">blahblahblahblah</div>
</div>
I would like to manipulate the html inside an iframe using jquery.
I thought I'd be able to do this by setting the context of the jQuery function to be the document of the iframe, something like:
$(function(){//document ready
$('some selector', frames['nameOfMyIframe'].document).doStuff()
});
However this doesn't seem to work. A bit of inspection shows me that the variables in frames['nameOfMyIframe'] are undefined unless I wait a while for the iframe to load. However, when the iframe loads the variables are unaccessible (I get permission denied type errors).
Does anyone know of way to work around this?
I want to split certain text using JavaSscript. The text looks like:
9:30 pm
The user did action A.
10:30 pm
Welcome, user John Doe.
11:30 am
Messaged user John Doe
Now, I want to split the string into events. i.e.:
9:30 pm
The user did action A.
would be one event. I'm using RegEx for this:
var split = journals.split(/\d*\d:/);
Thing is, the first two characters are getting lost. The split appears like this:
30 pm
The user did action A.
How do I split so that the split maintains the first two/three characters (ie 9: or 10:) etc?
Thanks!
Quick question.
I have a js function which gets called on the page every few seconds. It's an ajax update thing.
Being a function, I declare local variables. I don't want to use closures or global variables for various reasons.
I'd never considered this, but do I need to release/clear the variables at the end of the function to release memory or will js do this for me automatically ?
Thanks
I'm just learning JS, trying to do things without jQuery, and I want to make something similar to this however I want to use an array of images instead of just the one.
My image array is formed like this
var image_array = new Array()
image_array[0] = "image1.jpg"
image_array[1] = "image2.jpg"
And the canvas element is written like this. (Pretty much entirely taken from the Mozilla site)
function draw() {
var ctx = document.getElementById('canvas').getContext('2d');
var img = new Image();
img.src = 'sample.png';
img.onload = function(){
for (i=0;i<5;i++){
for (j=0;j<9;j++){
ctx.drawImage(img,j*126,i*126,126,126);
}
}
}
}
It uses the image "sample.png" in that code but I want to change it to display an image from the array. Displaying a different one each time it loops.
Apoligies if I've not explained this well.
I have some code here : http://bitbucket.org/natim/lo53_tp1/src/tip/part3/camions/medias/js/tracking.js
That I use to draw some information about trucks direction.
The problem come from a function defined in a for loop like this one :
...
for(i = 0; i < nb_trucks; i++)
{
...
contentString = '<div id="content">'+ trucks[i]['name'] + '</div>';
current_window = new google.maps.InfoWindow({
content: contentString
});
infosWindow.push(current_window);
current_marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(trucks[i]['end']['lat'], trucks[i]['end']['lon']),
draggable: false,
title: trucks[i]['name']
});
markers.push(current_marker);
google.maps.event.addListener(current_marker, 'click', function() {
current_window.open(map, current_marker);
});
}
In this code, you can see the last block
google.maps.event.addListener(current_marker, 'click', function() {
current_window.open(map, current_marker);
});
And my problem is that current_marker in the addListener parameters is different from the one inside the function.
The current_window and the current_marker inside the function is overide at each loop turn.
How can I get it right ?
Thanks
I have the following code sample that im trying to wrap my head around
$(document).ready(function () {
test("load json", function () {
length = 0; // length = 0
$.getJSON("plugins/form.json", function (data) {
length = data.fields.length; // length = 4
});
ok(length == 4, "length = " + length.toString()); // length = 0? wtf?
});
});
the 'length' variable does not persist when the $.getJSON runs. I cant figure out if its because its asynchronous or because the variable is out of scope.
I'm trying to integrate Mixpanel with GWT, but I have problems calling an event with a property and one value.
My function to track an simple event (without values):
public native void trackEvent(String eventName)/*-{
$wnd.mixpanel.track(eventName);
}-*/;
It works.
But when I want to add some properties and values, it doesn't work properly:
public native void trackComplexEvent(String eventName, String property,
String value)/*-{
$wnd.mixpanel.track(eventName, {property:value});
}-*/;
I have 2 problems with this:
1) Mixpanel says the property name is: "property"(yes, the name of the variable that I'm passing, not the value).
2) Mixpanel says the value is:undefined
An example from mixpanel web is:
mixpanel.track("Video Play", {"age": 13, "gender": "male"});
So, I guess the problem is I'm doing a wrong call or with wrong type of arguments.
I have a three strings of categories
"SharePoint,Azure,IT";
"BizTalk,Finance";
"SharePoint,Finance";
I need to find a way to check if a string contains for example "SharePoint" and "IT", or "BizTalk" and "Finance". The tests are individual strings themselces.
How would i loop through all the category strings (1 - 3) and only return the ones which have ALL instances of the souce.
i have tried the following
function doesExist(source, filterArray)
{
var substr = filterArray.split(" ");
jQuery.each(substr, function() {
var filterTest = this;
if(source.indexOf(filterTest) != -1 )
{
alert("true");
return true;
}else
{
alert("false");
return false;
}
});
}
with little success...the code above checks one at a time rather than both so the results returned are incorrect. Any help would be great.
Thanks
Chris
UPDATE: here is a link to a work in progress version..http://www.invisiblewebdesign.co.uk/temp/filter/#
I have a callback function in my open social application which fetches remote date. This works perfect on Crome and Mozila browers but not in IE8. Following is the example for the same, help will be appriciated:
This funcation: gadgets.io.makeRequest(url, response, params) makes the callback call
and following function process the responce:
function response(obj) {
var str = obj.text;
var offerDtlPg = str.substr(0, str.length);
document.getElementById('pplOfrDetls').innerHTML = offerDtlPg;
};
How to create regex pattern which is concatenate with variable, something like this:
var test ="52";
var re = new RegExp("/\b"+test+"\b/");
alert('51,52,53'.match(re));
Thanks
I have a Scripts folder, that includes all the .js files used in the project. Using the Ajax Minifier task, I generate .min.js files for each one.
Depending on whether the application is running in debug or release mode, I include the original .js file, or the minified one.
The Scripts folder looks like this:
Scripts/script1.js
Scripts/script1.min.js // Outside the project, generated automatically on build
Scripts/script2.js
Scripts/script2.min.js // Outside the project, generated automatically on build
The .min.js files are outside the project (although in the same folder as the original files), and they are not copied into the destination folder when we publish the project.
I have no experience whatsoever using build tasks (well, apart from including the minifier task), so I would appreciate if anyone could advise me as to which would be the correct way to:
Copy the .min.js files to the destination folder when I publish the app from Visual Studio.
Delete / Not copy the original js files (this is not vital, but I'd rather not copy files that will not be used in the app).
Thanks,
I'm building a phonehap application. I'm using an web sql and everything works fine till data retival.
function getItemGroups(){
var items_groups = new Array();
var db = window.openDatabase("merbokDB", "1.0", "MerbokDB", 5232394);
db.transaction(
function(tx){
tx.executeSql('SELECT * FROM item_groups',[],
function(tx,result){
if(result.rows.length > 0){
var len = result.rows.length;
for (var i=0; i<len; i++){
items_groups.push(result.rows.item(i).item_group);
}
console.log(items_groups.join());
}
}
,errorCB);
},
errorCB);
return items_groups;
}
var myproducts = getItemGroups();
My problem was when I run the code "myproducts" variable is blank. but the I can see
console.log(items_groups.join());
following line printing the values in console. Is I'm wrong in the way I returning?
function primeNumbers() {
array = [];
for (var i = 2; array.length < 100; i++) {
for (var count = 2; count < i; count++) {
var divisorFound = false;
if (i % count === 0) {
divisorFound = true;
break;
}
}
if (divisorFound == false) {array.push[i];}
}
return array;
}
When I run this code, it seems to get stuck in an infinite loop and doesn't return anything... why?
In Firefox console, this code will generate error:
{"d" : ["bankaccountnumber", "$1234.56"] }
SyntaxError: invalid label {
message="invalid label", more...}
this code works just fine
{d : ["bankaccountnumber", "$1234.56"] }
["bankaccountnumber", "$1234.56"]
this code works fine as well
var act = {'d' : ["bankaccountnumber", "$1234.56"] }
a.d
Can someone help to explain why is the diference? thanks!