Getting App Name from inside the HTML UIWebView
Let's say I'm displaying a webpage inside of native iPhone app called FooBar using UIWebView. I then want to display the name of the Application (in this case FooBar) I'm running inside the开发者_StackOverflow webpage dynamically (Hello Foobar). Is there a way through JavaScript (or any other mechanism) to get the App Name from within the HTML?
To think of another way. Let's say have I have web page that acts differently based on whether I open it through Safari on y Mac, Safari on my iPhone, my Foobar native App. Can I do that?
This document should clear things up nicely. Basically you just create a Javascript string and then call the following method of UIWebView:
-(NSString*) stringByEvaluatingJavaScriptFromString:(NSString*)string;
Make Javascript to add the app name to the header/title/wherever. Push that into an Objective-C NSString object and pass it to this method. As long as your HTML lines up you should be good to go!
You can use a user agent sniff to detect browser and OS. You can then redirect the user based on what browser and OS they accessed the site with to other pages or domains or serve up dynamic content accordingly.
Quirksmode Javascript User Agent Page
精彩评论