views:

63

answers:

1

I'm try to use accelerator Titanium to add native commands to a webapp.

http://appcelerator.com/

I'm changing the window location to an external website like this:

window.location = http://site.com;

I want to bind events on that website.

$('a').click(function () {
  alert('clicked');
});

The site has jquery loaded, the index.html also has jQuery included. But I suppose the index.html having jQuery has nothing to do with it since I changed the location already.

In any case the above does not work.

Can anyone tell me if it's possible.

To rephrase, what I want to do is use custom javascript and titanium commands on a website, sort of like a browser plugin?

Can anyone help with this?

Thanks.

A: 

If I understand correctly you want to do something like Greasemonkey does for Firefox. The problem is that you can not do such a thing because of browser restriction. What you are trying to do is the same thing as attackers do when they are exploiting XSS vulnerabilities.

mhitza
Yes but titanium allows me to create my own browser, so I should be able to do this.
Mark
You might try to observe the "load" event for the WebView and in the event handler use the "evalJS" of the WebView to execute the code, but then you'd have to make some restriction as for what urls to execute the code.
mhitza
@mhitza thanks a lot, sounds like what I need. Do you have a reference link or could you please provide some example code? Thanks.
Mark
I haven't worked with titanium, but have taken the information from the UI.WebView reference http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.WebView-object.html
mhitza