how to use windowScriptObject on the iPhone? - javascript

Greetings!
I was wondering how I could use javascript code on an iPhone application I was developing. this tutorial illustrated how to use windowScriptObjects for Cocoa application. However, I have been unable to locate something similar for UIWebViews.
does this functionality actually exist in Cocoa touch? and if yes, could anyone point me to the right direction as to how I might start using it.
thank you once again

Like rpetrich said, this is Non-Public API so the windowScriptObject route might not be the best.
I did find this link though, which helped me a lot:
https://discussions.apple.com/message/7731057?messageID=7731057&#7731057
Basically, if you can keep your interactions between HTML and Objective-C entirely based on the user clicking links ( a href="" )
then all of this can be easily communicated between the two.
While it would be nice, I agree, to exchange variables and call methods at will, this already gives you a lot to work with. Hope that's useful!

This functionality is not exposed via a public API.

Related

Where could I find the useable-native-apis when coding NativeScript App?

The article accessing-native-apis-with-javascript tells us how to use naive-Apis with js code. It is good.
But, I don't know where is the native-Apis because I never come into Android. Is it a necessary to know basic of Android knowledges for all Nativescript learner?
So I turned to Android developer site to find the list, and I falled in an other rabbit hole. It is so complicate to me.
Can you give us a usable-native-Apis-list to access the native-Apis easily?
For example, I want to use device's contacts in my App, so I turn to Android-developer-guide site to find which API is the right one. I get a lot of APIs named "contact****", which one is the target? It's painful to seek the answer for a learner of Nativescript.
"The beauty of Nativescript is .....", I turn to Nativescript just because of these words.
But, if I should learn about all the native APIs to see the beauty in the end?
when you need to use native api , you can search for that , and you will find java code for that for example https://stackoverflow.com/a/12562234/4146943
In this answer you need getContentResolver then you search in android docs to get the package name of getContentResolver https://developer.android.com/reference/android/content/Context.html#getContentResolver()
In the begin of page you see android.content.Context so you can use android.content.Context.getContentResolver
Note :
knowing java and a little android develope with java wold really help.
Note2 : checking other plugins to see how others use native api really helps.

Creating a note taking app using JQuery mobile and phone gap

I have an app i'm developing with JQ Mobile and PhoneGap. Within this app, i want to include a 'Notes Taking' page and it has to do the following.
Make new notes and save them locally.
Recall them whenever i need to,
Edit them and delete them
i could not find a good example to follow, i tried this:
http://tutorialzine.com/2012/09/simple-note-taking-app-ajax/
but he lost me at the index php and how to implement that, i also tried this example:
http://miamicoder.com/2011/building-a-jquery-mobile-application-part-1/
but its so complex i got lost in all the code.
I'm a beginner at programming and my JavaScript is very very poor and i have no idea where to start and what kind of code is involved in making this part of the app.
Please help. Thank you.
Your first site (http://tutorialzine.com/2012/09/simple-note-taking-app-ajax/) will not work for you as the examples are embedding PHP into the html and that is not acceptable with phonegap apps.
Your second site is making it way more complicated than it needs to be for your limited scope.
Not going to do this for you but I will give you some advice and places to look.
Draw out what you want the user interface to look like and create that html
Create a load and save function in javascript to... well... load and save your notes. Take a look at the below references:
This will show you how to interact with the local database and store and retrieve info. Always a good thing to read the documentation.
This is a great resource for help all sorts of stuff. In this case, with SQL queries.
Test, test, test. With the above, you will be able to figure it out if you put your mind to it. Come back here and post specific questions with code samples of what you have tried if you get stuck.

Automated Testing with Javascript for any web app - need more suggestions and ideas

BACKGROUND: I've been looking for auto-testing tools for my web-app developed in C# having AJAX. I tried to find some tools but some were complex, some were paid and some would not allow me to tweak in. Some are listed below but I wanted something on which I had the total control and would be v.light weight and easily portable.
My inspirations :)
http://watin.sourceforge.net
http://sahi.co.in/w/
http://seleniumhq.org/projects/ide/
SOLUTION: So, finally getting back to my old javascript skills I ended up creating my own simple (and hopefully effective) auto-testing tool! The idea was to create a wrapper parent html page which will 'host' the web-page to be tested in an iframe and then access its controls, populate value and perform clicks, etc...
*NOTE: Both the pages need to be on the same machine to be tested (cross
domain testing is not allowed)
Here's a sample image explaining my method -
And here's the wrapper page
code : http://www.codeupload.com/3813
I'd like to know your suggestions and idea about the same and what you prefer. I see many usage of this method like - auto-testing, showing an automated demo, automated-data-entry,... but everything on the same domain.
Here's my codeproject article:
http://www.codeproject.com/KB/custom-controls/JS-Automated-Testing.aspx
Please share your thoughts. And if some one is interested I've also posted a youtube video showing it live in action:
http://www.youtube.com/watch?v=j_z_IrFztBo
Thank you
PS: Hope this is not misleading, I'm not advertising, its just for sharing and learning ;)

Where can I get advice on how to build completely ajax web apps?

I am building a completely ajax web app (this is the first web app I have ever created). I am not exactly sure if I am going about it the right way. Any suggestions or places where I can go to find suggestions?
Update:
I currently am using jQuery. I am working on fully learning that. I have designed a UI almost completely. I am struggling in some parts trying to balance a good UX, good design and fitting all the options I want to fit in it.
I have started with the design. I am currently struggling with whether to use absolute positioning or not and if not how do I use float etc. to do the same type of thing. I am trying to make it have a liquid layout (I hate fixed-layout pages) and am trying to figure out what I should use to make it look the same in most screen sizes.
Understand JavaScript. Know what a closure is, how JavaScript's event handling works, how JavaScript interacts with the DOM (beyond simply using jQuery), prototypal inheritance, and other things. It will help you when your code doesn't work and you need to fix it.
Maintain usability. All the AJAX magic you add is useless if users cannot figure out how to use it. Keep things simple, don't overload the user by giving him information he doesn't need to know (hide less important information, allowing the user to click a link to show it), and if possible, test your app with actual users to make sure that the interface is intuitive to them.
Code securely. Do not allow your server to get hacked. There are many different types of security flaws in web apps, including cross-site scripting (XSS), cross-site request forgery (CSRF), and SQL injection. You need to be well aware of these and other pitfalls and how to avoid them.
One starting point is to look at the Javascript Libraries and decide which one to use:
http://code.google.com/apis/libraries/
http://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks
You probably don't want to do raw Javascript code without any library. Once you decide on a library to use, then you can look at its documentations online or the books about using them. jQuery does have pretty good documentation.
Define "right way."
There are many "right ways" to code an app.
Things to keep in mind are trying to design a nice interface. The interface can make or break an application and studies show that it can even make it seem faster if you do it right. jQuery is good for this.
Another thing to consider going in is what browsers do you want to support? Firefox is really doing well and Google Chrome's market share is growing so you will want so support those for sure. IE is a tough one as it doesn't have the best support for standards, but if you are selling a product you will really want this.
One of the best articles that I've ever come across about the structure of an ajax web application is this one. A little outdated because it refers to XML as the primary data-interchange format, now JSON. jQuery, a javascript framework, contains excellent functionality for both DOM manipulation and AJAX calls. Both are a must in any AJAX-driven web app.

Scraping websites with Javascript enabled?

I'm trying to scrape and submit information to websites that heavily rely on Javascript to do most of its actions. The website won't even work when i disable Javascript in my browser.
I've searched for some solutions on Google and SO and there was someone who suggested i should reverse engineer the Javascript, but i have no idea how to do that.
So far i've been using Mechanize and it works on websites that don't require Javascript.
Is there any way to access websites that use Javascript by using urllib2 or something similar?
I'm also willing to learn Javascript, if that's what it takes.
I wrote a small tutorial on this subject, this might help:
http://koaning.io.s3-website.eu-west-2.amazonaws.com/dynamic-scraping-with-python.html
Basically what you do is you have the selenium library pretend that it is a firefox browser, the browser will wait until all javascript has loaded before it continues passing you the html string. Once you have this string, you can then parse it with beautifulsoup.
I've had exactly the same problem. It is not simple at all, but I finally found a great solution, using PyQt4.QtWebKit.
You will find the explanations on this webpage : http://blog.motane.lu/2009/07/07/downloading-a-pages-content-with-python-and-webkit/
I've tested it, I currently use it, and that's great !
Its great advantage is that it can run on a server, only using X, without a graphic environment.
You should look into using Ghost, a Python library that wraps the PyQt4 + WebKit hack.
This makes g the WebKit client:
import ghost
g = ghost.Ghost()
You can grab a page with g.open(url) and then g.content will evaluate to the document in its current state.
Ghost has other cool features, like injecting JS and some form filling methods, and you can pass the resulting document to BeautifulSoup and so on: soup = bs4.BeautifulSoup(g.content).
So far, Ghost is the only thing I've found that makes this kind of thing easy in Python. The only limitation I've come across is that you can't easily create more than one instance of the client object, ghost.Ghost, but you could work around that.
Check out crowbar. I haven't had any experience with it, but I was curious about the answer to your question so I started googling around. I'd like to know if this works out for you.
http://grep.codeconsult.ch/2007/02/24/crowbar-scrape-javascript-generated-pages-via-gecko-and-rest/
Maybe you could use Selenium Webdriver, which has python bindings I believe. I think it's mainly used as a tool for testing websites, but I guess it should be usable for scraping too.
I would actually suggest using Selenium. Its mainly designed for testing Web-Applications from a "user perspective however it is basically a "FireFox" driver. I've actually used it for this purpose ... although I was scraping an dynamic AJAX webpage. As long as the Javascript form has a recognizable "Anchor Text" that Selenium can "click" everything should sort itself out.
Hope that helps

Categories

Resources