nextwebgen.com

The Next Generation Web Now

Eval’ing with IE’s window.execScript

Filed under: Web 2.0 News — Michael Mahemoff at 3:40 pm on Wednesday, January 31, 2007

Plaxo’s Joseph Smarr has been playing with on-demand javascript, i.e. downloading extra JS code after the page has already loaded. When you grab the code via a remote call and eval() it, it doesn’t get into global scope. So here’s how he dealt with it.

Here’s a simplified version of the situation we faced:

function loadMyFuncModule() {
  // imagine this was loaded via XHR/etc
  var code = 'function myFunc() { alert(\"myFunc\"); }';
  return eval(code); // doesn’t work in FF or IE
}
	
function runApp() {
  loadMyFuncModule(); // load extra code “on demand”
  myFunc(); // execute newly loaded code
}

The thing to note above is that just calling eval() doesn’t stick the code in global scope in either browser. Dojo’s loader code solves this in Firefox by creating a dj_global variable that points to the global scope and then calling eval on dj_global if possible:

function loadMyFuncModule() {
  // imagine this was loaded via XHR/etc
  var code = 'function myFunc() { alert(\"myFunc\"); }';
  var dj_global = this; // global scope object
  return dj_global.eval ? dj_global.eval(code) : eval(code);
}

This works in Firefox but not in IE (eval is not an object method in IE). So what to do? The answer turns out to be that you can use a proprietary IE method window.execScript to eval code in the global scope (thanks to Ryan “Roger” Moore on our team for figuring this out). The only thing to note about execScript is that it does NOT return any value (unlike eval). However when we’re just loading code on-demand, we aren’t returning anything so this doesn’t matter.

The final working code looks like this:

function loadMyFuncModule() {
  var dj_global = this; // global scope reference
  if (window.execScript) {
	
    window.execScript(code); // eval in global scope for IE
    return null; // execScript doesn’t return anything
  }
  return dj_global.eval ? dj_global.eval(code) : eval(code);
}
	
function runApp() {
  loadMyFuncModule(); // load extra code “on demand”
  myFunc(); // execute newly loaded code
}

And once again all is well in the world.

Sound with JavaScript but not Flash

Filed under: Web 2.0 News — Dion Almaer at 2:55 pm on Wednesday, January 31, 2007

Reinier Zwitserloot wanted to see if he could add sound support without embedding a Flash bridge, and shared his research in his article on Sound in Web Browsers without Flash.

Check out his test page for a Sound Check

An example API

JAVASCRIPT:
  1.  
  2.                         function sound2Play() {
  3.                                 if ( !sound2Embed ) {
  4.                                         sound2Embed = document.createElement("embed");
  5.                                         sound2Embed.setAttribute("src", "machinegun.wav");
  6.                                         sound2Embed.setAttribute("hidden", true);
  7.                                         sound2Embed.setAttribute("autostart", true);
  8.                                 } else sound2Stop();
  9.                                 sound2Embed.removed = false;
  10.                                 document.body.appendChild(sound2Embed);
  11.                         }
  12.                        
  13.                         function sound2Stop() {
  14.                                 if ( sound2Embed && !sound2Embed.removed ) {
  15.                                         document.body.removeChild(sound2Embed);
  16.                                         sound2Embed.removed = true;
  17.                                 }
  18.                         }
  19.  

Web 2.0 in 2007: Brands rule! - ZDNet

Filed under: Web 2.0 News — web 2.0 - Google News at 2:30 pm on Wednesday, January 31, 2007


ZDNet
Web 2.0 in 2007: Brands rule!
ZDNet - 3 hours ago
Web 2.0 social networking systems are equally bombastic: “Users are in control.” To reach the frothy financial goals, both MySpace and Facebook are ...

Kodiak Networks Announces Solution for Mobile Web 2.0 - Wireless Week

Filed under: Web 2.0 News — web 2.0 - Google News at 12:26 pm on Wednesday, January 31, 2007

Kodiak Networks Announces Solution for Mobile Web 2.0
Wireless Week - 1 hour ago
By Eric M. Zeman. Kodiak is answering network operator demand for mobile applications that are group-oriented and can be downloaded to or preloaded on ...

SmarterTools Announces SmarterMail 4.0 with AJAX Web Interface - JavaScriptSearch (press release)

Filed under: Web 2.0 News — Ajax - Google News at 10:50 am on Wednesday, January 31, 2007


JavaScriptSearch (press release)
SmarterTools Announces SmarterMail 4.0 with AJAX Web Interface
JavaScriptSearch (press release), IL - 1 hour ago
SmarterTools, Inc. announced the release of SmarterMail 4.0 with a virtually spam-free environment and a new AJAX Web interface without sacrificing ...
SmarterMail 4.0 With AJAX Web Interface Unveiled SYS-CON Media
all 5 news articles

DEMO 2007 Embraces Web 2.0 - PC Magazine

Filed under: Web 2.0 News — web 2.0 - Google News at 10:02 am on Wednesday, January 31, 2007

DEMO 2007 Embraces Web 2.0
PC Magazine - 1 hour ago
PALM SPRINGS—If you think Web 2.0 is "so over," you're not at this year's DEMO 07 Conference in Palm Desert, CA. The exclusive conference, which runs ...

Can Mainstream Media’s Adoption of RSS and Web 2.0 Spur Consumer … - Search Engine Watch

Filed under: Web 2.0 News — web 2.0 - Google News at 9:39 am on Wednesday, January 31, 2007

Can Mainstream Media’s Adoption of RSS and Web 2.0 Spur Consumer
Search Engine Watch - 21 minutes ago
Alex Iskold in Read/Write Web surveys the number of prominent mainstream media publications that have added Web 2.0 buttons to their pages.

The security implications of Web 2.0 - SC Magazine

Filed under: Web 2.0 News — web 2.0 - Google News at 8:25 am on Wednesday, January 31, 2007

The security implications of Web 2.0
SC Magazine, UK - 1 hour ago
The same complexities we see with a fully loaded car apply to web functionality. Web 2.0 has arrived, and the race to adopt it has brought with it ...
« Previous PageNext Page »