Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Highlighted
New Developer
Posts: 4
Registered: ‎02-03-2009
My Device: Not Specified

location.href javaScript Problem

Hello,

 

I tried the search function, but could not find anything helpful...

 

I'm trying to run a really simple JavaScript in a BB Brower (OS 4.2.x on a BB 8820).

 

JavaScript is turned on, as well as JavaScript Popup support.

 

Nevertheless, the script stops working after the alert() message.

In a regular web browser on my computer the script runs flawless.

 

Here the script:

[code]

<script language="JavaScript" type="text/javascript">
function colorCart ()
{
var page = "xyz.php";
displmsg=confirm('Do you really want to color the entire cart?');
if (displmsg==true)
{
location = page + '?color=green';
}
}
</script>

[/code]

 

Maybe somebody knows whats wrong...

It's my first time programming something for a BB.

 

Thanks for any support!

Osinho

Guru I
Posts: 19,017
Registered: ‎07-29-2008
My Device: Passport, Playbook, 9320BES
My Carrier: Bouygues _ SFR

Re: location.href javaScript Problem

which alert() function are you talking about?



The search box on top-right of this page is your true friend, and the public Knowledge Base too:
New Developer
Posts: 4
Registered: ‎02-03-2009
My Device: Not Specified

Re: location.href javaScript Problem

Oops,

You are right.

I mean confirm().

But the problem remains...

After clicking ok the script does not continue on the BB.
Guru I
Posts: 19,017
Registered: ‎07-29-2008
My Device: Passport, Playbook, 9320BES
My Carrier: Bouygues _ SFR

Re: location.href javaScript Problem

I am a bit lazy. Can you publish the page containing that small script and give the url ?



The search box on top-right of this page is your true friend, and the public Knowledge Base too:
Developer
Posts: 107
Registered: ‎09-25-2008
My Device: Not Specified

Re: location.href javaScript Problem

Try using window.location instead of just location. The javascript support on 4.2 is pretty bad and I wouldn't be surprised if that fixes it.
New Developer
Posts: 4
Registered: ‎02-03-2009
My Device: Not Specified

Re: location.href javaScript Problem

Thank you very much for your replies.

Will try the window. solution first thing when I get to work tomorrow. Right now I'm writing on my iPhone so I can't really do anything. If that doesn't work I will post a link to a live page, so you can see and try yourselves..

Again, thanks a lot for any help.
Osinho
New Developer
Posts: 4
Registered: ‎02-03-2009
My Device: Not Specified

Re: location.href javaScript Problem

THANK YOU VERY MUCH!!!

window.location did the trick!

 

Man, I wished BB would come up with a "real" version JavaScript!!

 

THX again!

Osinho

Guru I
Posts: 19,017
Registered: ‎07-29-2008
My Device: Passport, Playbook, 9320BES
My Carrier: Bouygues _ SFR

Re: location.href javaScript Problem

hello,

location is a method of object window, there is no reason why you should be able to call it without reference to the window object. Browsers that do that do not do real Javascript, they do more (a superset of that language, in order to compensate the lack of discipline of the developer)



The search box on top-right of this page is your true friend, and the public Knowledge Base too:
Developer
Posts: 107
Registered: ‎09-25-2008
My Device: Not Specified

Re: location.href javaScript Problem

No, osinho is right. In the browser world, the window object is defined to be the same as the global object in ecma-262. So anything on the window object should be in global scope and accessible without using "window.". Earlier versions of the blackberry browser had pretty bad support for javascript and so this doesn't work as correct. In 4.6 and higher, with the new rendering engine, this works as expected.
Developer
Posts: 189
Registered: ‎08-13-2008
My Device: Not Specified

Re: location.href javaScript Problem

Hello Guys

 

Something I have noticed in testing is that some versions don't work with

document.location =

 so I changed to

 document.location.href =

 

and this syntax seems to work in all versions.

 

Cheers

Andrew