Not sure how useful this is, exactly. It requires a bit of explanation.
function assert(assertString, thisObj) {
var throwException = arguments.length > 2 ? arguments[2] : false;
var argsObj = arguments.length > 3 ? arguments[3] : {};
var argsString = "";
for (var property in argsObj) {
argsString += ("var " + property + " = " + argsObj[property].toSource() +";
");
}
var func = new Function(argsString + "return (" + assertString + ");");
var mustBeTrue = false;
try {
mustBeTrue = func.apply(thisObj);
}
catch(e) {
// fall through. An exception will leave mustBeTrue as false, and the assertion still fails.
}
try {
if (!mustBeTrue) {
throw new Error("ECMAScript assertion failed: (" + assertString + ")");
}
}
catch(e) {
if (throwException) {
/* For Mozilla, use
throw new Error(e.message + " stack:
" + e.stack);
*/
throw e;
} else {
/* For Mozilla, use
dump ("Warning: " + e.message + " stack:
" + e.stack);
for (property in argsObj) {
dump(property + " = " + argsObj[property] + "
");
}
dump("
");
*/
alert(e);
}
}
return mustBeTrue;
}
So what is an assert()? In C++, it's usually a macro the programmer uses to test a statement that must be true for the code to function properly. The statement, I believe, is called an assertion.
If the assertion evaluates to false, then there's a bug in the program. It's basically a way for the programmer to detect for bugs in the program that the program wouldn't be expected to know about.
This assert() function takes a string as its first argument, which must evaluate to true. If said string is true, everything's hunky-dory, and the function returns true. If said string is false, then the function notifies either the user or the application (depending on the third argument, which is optional), and returns false. If there is an exception generated while testing the assertion, the assert() function returns false.
The second argument is the this object of the code calling the assert(). So you could basically call the assert() like this:
assert("1 == 1", this);
The optional third argument, which defaults to false, determines if a JavaScript error should be thrown. A false value means notify the user, but don't stop execution (dump() is a Mozilla-specific function, used in debug builds). A true value means throw the exception.
The fourth argument should be an object literal for passing variables into the assertion for evaluation. For instance:
if (assert("x == 1", this, false, {
x: 1
} )) {
html_input.value = "x is indeed equal to one!";
}
All this works because the assert() function creates a local function object based on the information you feed it, and then executes that function.
This code is available under the Mozilla Public License (MPL1.1) tri-license scheme. Feedback?
I like it because everything is modular, the submenus stays within the shape of the rectangle without jutting out horizontally across the website. However, when I tried to tweak with the code some of the images just wouldn't show up. I saved the ENTIRE website but modifying the names of the images just didn't work. As a result I am comtemplating on doing this same menu in Flash. (loading the same positioned swf on top of another, on top of another).
I have a web-application project which requires interactive User Interfaces. It is more like a web based xml content editor. I have seen a few javascript based text editors but not much flash based ones. I dont have much experience on neither of the technologies so I have to spent some time to develop my skills on them (your suggestions are wellcome:) my questions are:
1. Is JavaScript and the today's internet users's enveronment (browser-speed-security) mature enough to run a heavy javascript based web application ?
2. I have the "sceptic feeling" that with Javascript, programmers have very little control on runtime environment or javascript behaviours, errors are not so predictable on client site. (Still I see lots of websites with javascript and a yellow Error sign on my browsers left bottom corner). Is it still quite complicated task to make the javascript run properly on most of the users site (say 90%) without complicated browser/version/DOM tricks and customisation?
3. Is Flash a better option for a interactive UI application? If so why is it still just an "animation" technology?
4. Is it possible (and easy) to mix the Flash with other technologies like Ajax or ASP.NET ? Is it possible (and available) to make flash-based components (like special behaviour combo box, or new kind of UI components) which can be used in an asp.net web application?
I have created a very simple HTML base photo album integrated with Google Maps.You can share your photo and the place where it was taken on a map. I tried to make it as straightforward I could. There is only a single XML file a user has to edit to use this album.
I have seen this employed somewhere else, but for the life of me cannot remember how it was done. I need to write a javascript that will call a desired CSS file based on the user's browser.
I'm working on some code and am running into brick walls. I'm trying to write out Javascript with Javascript and I've read the clj Meta FAQ and didn't see the answer, read many similar posts (with no luck though), and searched through the IRT.ORG Faqs (www.irt.org/script/script.htm).
The Javascript is designed to open an popup window and then inside that window call another script which will resize that window. There may be another way around this but the reason I tried this approach initially was that I wanted to call the onload handler in the popup window to resize the image only after the image had completely loaded. I've had some code in the primary Javascript file (showimage.js) before that works if the image has been cached but on the first load, it doesn't resize properly which tells me it is probably because it is trying to resize the window based on the image size but it isn't completely known at that point. So I removed that code and tried placing the resizing code in the second Javascript file (resizewindow.js). BTW I've tried other code to open a popup image and automatically size it ie Q1443 at irt.org but that doesn't do exactly what we need.
Even if there is another way to do this with one file, I still want to figure out why this isn't working in case I run into it in the future.
I thought what I would need to do to use document.writeln to write Javascript would be to escape any special characters and to break apart the script tag ie
document.writeln('</SCRIPT>');
would become
document.writeln('</SCR' + 'IPT>');
I have a HTML page and 2 Javascript files. All files are in the same directory and have permissions set correctly.
Here are the 3 files (keep in mind wordwrap has jacked up the formatting):
index.html ---------- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Test</title> <SCRIPT type="text/javascript" LANGUAGE="JavaScript1.1" SRC="showimage.js"> </SCRIPT> </head>
<body> Click the house<BR> <A ONCLICK="newWindow1('house1.jpg','Nice House')"><IMG SRC="house1thumb.jpg"></A> </body> </html>
showimage.js ------------ function newWindow1(pic,sitename) {
resizewindow.js --------------- function resizewindow() { // Do resizing here. // Right now this isn't being executed alert("resizing window"); }
Can anyone provide some pointers as to why this javascript is failing? I'm using IE6 on Win2k and when I click on the image to open the popup window, it does open the window but it is white with no content and the system immediately goes from about 4% CPU usage to 100% and consistently stays there until I kill that window with the task manager.
I'm getting errors in Firefox everytime I try to run this frame resize code, but it works fine in IE. I can't seem to figure out what the problem is with it.
The error is: Error: theFrame has no properties Line: 8
The line that the javascript console is showing an error for is in italics.
I would like to execute functions based on the value of a form. This is the code I have. <input type="text" id="posttitle" value="Title" onblur="if(this.value.length == 0) this.value='Title';" onfocus="if(this.value == 'Title') this.value='';"> Now let's say I want to execute the function "myFunction()" onblur if that same condition is met, so not only will it recreate the value "Title" but it will also execute a function afterwards. How can I achieve this? I assumed I'd do something like... onblur="if(this.value.length == 0) this.value='Title' myFunction();" But that did not work.
So I have a string which I want to use to call a function. How can I do this?. For example lets say I have a string = "function1". Now since I have this string I to use it to call code...
I have a script to show and hide various divs based on a function & var. The problem I am having is that when ANY of the variables ('hate', 'ok' and 'love') are passed all 3 different feedback forms ('FeedbackHate', 'FeedbackOk' and 'FeedbackLove') appear, not just the one I want.
Here is the JS: function sitesurveyswitch(emotion) { var e = emotion; document.getElementById('site_survey_hate').style.backgroundPosition = '0px 0px'; document.getElementById('site_survey_ok').style.backgroundPosition = '0px 0px'; document.getElementById('site_survey_love').style.backgroundPosition = '0px 0px'; document.getElementById('FeedbackHate').style.display = 'none'; document.getElementById('FeedbackOk').style.display = 'none'; document.getElementById('FeedbackLove').style.display = 'none'; if (e == 'hate') document.getElementById('site_survey_hate').style.backgroundPosition = '-80px 0px'; document.getElementById('FeedbackHate').style.display = 'block'; if (e == 'ok') document.getElementById('site_survey_ok').style.backgroundPosition = '-80px 0px'; document.getElementById('FeedbackOk').style.display = 'block'; if (e == 'love') document.getElementById('site_survey_love').style.backgroundPosition = '-80px 0px'; document.getElementById('FeedbackLove').style.display = 'block'; }
And here is the code related to this function: <div id="siteSurveyBox"> <span id="site_survey_hate" onclick="sitesurveyswitch('hate');return false;"></span> <span id="site_survey_ok" onclick="sitesurveyswitch('ok');return false;"></span> <span id="site_survey_love" onclick="sitesurveyswitch('love');return false;"></span> </div> <div id="FeedbackHate" style="display:none; margin-top:-28px;"> FEEDBACK FORM IS HERE </div>
<div id="FeedbackOk" style="display:none; margin-top:-28px;"> FEEDBACK FORM IS HERE </div> <div id="FeedbackLove" style="display:none; margin-top:-28px;"> FEEDBACK FORM IS HERE </div>
All the function extending I see extends on an _object_. I want to extend on a string. /** * Returns a slug version of a string */ jQuery.extend ({ slug: function( text ) { return text.trim().toLowerCase().replace( /[^-a-zA-Z0-9s]/g,'' ).replace( /[s]/g, '-' ); }}); I want to be able to do something like: $('#form_element').val().slug(); The above does not work. I even tried modifying the 'trim' function in jQuery core to include the rest of the enhancements, but it didn't work.
I have some javascript that I have written into the <body> section and it works great. But I would like to make it into a javascript function and define the function in the <head> section. Then in the <body> section write a small bit of javascript that would call the function() object. Code:
Given the following input tag which is enclosed within a hidden div tag:<input id="X" class="Y"/> this call (id-based) locates the tag: $(this).find("#X")but this one doesn't (class-based)I couldn't find any documentation indicating find() working differently when using id-based vs class-based selectors.
I have three different web pages with different domains, and I want to show some pages of one of the webs in the others.
I use an iframe for this and it shows it good until I have to call a javascript function in the iframe inside page, I have a permission denied because the domains of these pages are different.
So, the cuestion is:
Is there some way to call the javascript function of the iframe from the parent page?
I'm working on a script(for giving points to a soccergame 0, 1 or 3 points) that give a value to a hidden field, i got a function but only works on 1 field.
I want that the function loops till all hidden fields are fill in.
In IE, it looks like you can have to many characters in a javascript function.
The content of an entire html page is put into this function...
function updateTemplate(content) { content=content.replace(/'/g, '''); content=content.replace(/"/g, '"'); content=content.replace(/</g, '<'); content=content.replace(/>/g, '>'); Element.update('template',content); } it seems to cut off the content after about 2060 characters. is that an IE thing or is there something wrong with my code. FF does it fine...