Link to home
Start Free TrialLog in
Avatar of btocakci
btocakciFlag for Türkiye

asked on

Executing a javascript function from url

hi, for some special reasons of mobile development (restrictions of cross-device platform called Marmalade API) i need a case like this:

From browser i will load a page. (That is normal)

On browser i need to suppy a URL for that:

Page will not be refreshed again but a javascript function inside the page will be executed.

Currently i can execute a function by some tricks. This is my url:

www.somedomain.com?action=alert('asd')

This really alerts what i want, but by refreshing on each request. I just need a feature such Firebug does. I tried bookmarklets and iframes with no success. Maybe you can help me on execute the js function without really requesting the page.This is really urgent. Thanks for your help.

Avatar of Somersault
Somersault
Flag of Sweden image

Hey!
There's a way to do this without refreshing. By using javascript: you can run any kind of javascript live in most browsers without having to reload the page.

When you have loaded the page, change your url from:

www.somedomain.com

To alert a string:
javascript:alert('This will be alerted');

To check the value of a variable:
javascript:alert('What value is foo? It is: ' + foo);

Run a method:
javascript:myFunction();

Hope that helps!

Cheers,
Chris
In case it wasn't clear, you just switch out your url with the javascript:... and submit it to fire the javascript.
Avatar of btocakci

ASKER

So what will be the exact value on browser's URL area? Simply this?

javascript:alert('This will be alerted');

It did nothing. Sorry for my lack of knowledge on this.
Because this url will be supplied by mobile application. Not by user clicking a link or sth.
Okay, what browser are you using to test this in at the moment?
firefox 7.0.1
ASKER CERTIFIED SOLUTION
Avatar of Somersault
Somersault
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, in-app browser's url will be changed by application.
ok, it also worked in my environment. Thanks.