2
votes

I am trying to add Readability (a third party app) compatibility with my web browser, and I tracked down a bookmarklet to save a page to Readability:

javascript:(%28function%28%29%7Bwindow.baseUrl%3D%27http%3A//www.readability.com%27%3Bwindow.readabilityToken%3D%27bbRmvVb9nTNRWSVEGb9yrcFP4USUHnTjk2EVWXjn%27%3Bvar%20s%3Ddocument.createElement%28%27script%27%29%3Bs.setAttribute%28%27type%27%2C%27text/javascript%27%29%3Bs.setAttribute%28%27charset%27%2C%27UTF-8%27%29%3Bs.setAttribute%28%27src%27%2CbaseUrl%2B%27/bookmarklet/read.js%27%29%3Bdocument.documentElement.appendChild%28s%29%3B%7D%29%28%29)

however, I can't seem to get it to work. It works in desktop Safari and mobile/iPhone Safari. But both of the methods below do nothing:

[webview stringByEvaluatingJavaScriptFromString: readability];

[webview loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString: readability]]];

(readability is a string with the value above)

Is there another method to run javascript bookmarklets that I am unaware of or am I doing something wrong? Help is much appreciated.

2
Your question does not make any sense. What does "am trying to add Readability compatibility with my web browser" mean? Where does webview stringByEvaluatingJavaScriptFromString: come from?DG.
Readability is a popular third-party app that saves webpages for offline reading. [webview stringByEvaluatingJavaScriptFromString:] is an objective C function that affects a UIWebView object.Greg

2 Answers

1
votes

Greg

You got this error is because the javascript url is encoded, you should decode the javascript string, (may be you use NSURL to pass the string, so it was encoded by NSURL)

then use the webview stringByEvaluatingJavaScriptFromString, this solution work well

-(void)loadUrl:(NSURL*)url
{
    if ([[url scheme] isEqualToString:@"javascript"])

    {
        NSRange range = [[url absoluteString] rangeOfString:@"javascript:"];
        NSString *javaScriptString = [[[url absoluteString] substringFromIndex:range.location + range.length] URLDecodedString];
        [self stringByEvaluatingJavaScriptFromString:javaScriptString];
    }
    else
    {
        [self loadRequest:[NSURLRequest requestWithURL:url]];
    }
}
0
votes

You probably need to use their API. What you are trying to do is likely prevented for security reasons, and you need to put your own API key in the request.