John M. Wargo

Twitter Feed

johnwargo: Here we go - First-time smartphone buyers favor Android over iOS: http://t.co/mQwxRHDP
johnwargo: Ummm, eating a handful of Dark Chocolate M&M's So good!
johnwargo: Working on the book's preface, hard 2 keep myself from saying 'the book you hold in your hand' since many won't ever actually hold the book
johnwargo: When sending an email to a group, why is it that Lotus Notes is smart enough to not send me a copy if I'm in the group but Outlook isn't?
johnwargo: Staying at a hotel without a gym. Ugh. I didn't even think to check to see if they had one, assumed they did.
Home BlackBerry Programmatically Enabling JavaScript in the BlackBerry Browser
Programmatically Enabling JavaScript in the BlackBerry Browser PDF Print E-mail
User Rating: / 3
PoorBest 
Monday, 26 October 2009 08:43

One of the most interesting things I learned while I was writing the book was how to enable JavaScript programmatically within the BlackBerry browser. As RIM reviewed the chapters, several people commented on how, even if JavaScript was turned off in the browser, it could be enabled programmatically. I searched and searched for information about how to do this, but couldn't find anything until I finally begged someone from RIM to explain to me how to do it. Here's how it's done:

In the NoScript section of an HTML page, put in some JavaScript. It doesn't have to be script that does anything, it just has to be JavaScript. When the browser encounters the JavaScript, it sees that it's disabled and prompts the user to enable it.

Here's a sample web page that enables this:

<!DOCTYPE html public "-//W3C//DTD HTML 4.01 Transitional//EN">
 <HTML>
 <HEAD>
 <TITLE>JavaScript Test</TITLE>
 </HEAD>
 </HEAD>
 <BODY>
<h1>JavaScript Test</h1>
 <SCRIPT type="text/javascript">
 document.write("JavaScript is enabled!")
 </SCRIPT>
 <NOSCRIPT>
 JavaScript is disabled!<br />
 Please <A href="javascript:void()">click here</A> to enable JavaScript.
 </NOSCRIPT>
 </BODY>
 </HTML>

What's interesting about how this works is that MDS will normally process the HTML page and remove any content not supported by the browser - it doesn't make any sense to send anything to the browser that the browser won't recognize. So, it the HTTP Accepts header indicates that JavaScript is not enabled, then MDS will remove all of the JavaScript code from the page. Since JavaScript isn't expected to be in the <NoScript> area of the page, MDS ignores it and delivers that script to the browser. When the link is clicked, the browser performs its check and prompts the user to enable JavaScript. 

Pretty cool, right?

 

Add comment


Security code
Refresh

InformIT (Pearson Education)