在目标 C 网站上执行外部 javascript
这是我的第一篇文章,所以我对我犯的任何错误感到抱歉:)
我知道标题很令人困惑,但我会尽力解释我想要的内容。
我得到了这个网站,在网站上有一个时间表,当你改变不同的值时,这个时间表就会改变,以便它与适当的人保持一致。当您更改值时,将调用 JavaScript 函数。我有什么办法可以从 Objective-C 执行此 JavaScript(在我不拥有的网站上)。
所以,我想要的是这样的(在一个非常简单的描述中):
do JavaScript call change()
on website: "My website" (我知道这是无效的,但这就是我想要的)
另外我希望能够更改不同的值并传递带参数的函数。
谢谢克里斯蒂安
,
网站在这里(挪威语):
http://www.novasoftware.se/webviewer/(S(mfq2npum0th2lxb0g5oy3045))/design1.aspx?schoolid=60810&code=545354&type=3&id=1559)
编辑:
你好,我找到了另一种方法来解决我的问题。
该网站会自动为每个学生生成一张图像。图像的 url 类似于此 链接
(发布网址时遇到一些问题)
您在哪里获得&week=42
(您可以将其更改为您想要的任何内容并且效果完美)。所以我让它在 MAC 上工作(在 Safari 5 中)。
但是当我尝试在 iPhone 模拟器中使用此 URL 时,我只看到白屏。
这是我使用的代码:
[webView loadRequest:[NSURLRequest] requestWithURL:[NSURL URLWithString:@"http://www.novasoftware.se/ImgGen/schedulegenerator.aspx?format=png&schoolid=60810/nb-no&type=3&id={76C567C0-161E-42C3-B054-8941DDD04F52} &period=&week=42&mode=0&printer=0&colors=32&head=0&clock=0&foot=0&day=0&width=1405&height=683&maxwidth=1405& maxheight=683"]]];
如果我使用像“http://www.google.com”这样的更简单的网址,它会起作用:S iPhone不支持aspx?
This is my first post so I am sorry for any mistakes I made :)
I know the title is confusing, but i will try to explain what I want.
I got this website, on the website there is a schedule, this schedule change when you change different values so that it consist with the appropriate person. When you change a value a JavaScript function is called. Is there any way for me to do this JavaScript (on a site I don't own) from objective-C.
So, what I want is this (in a very plain description):
do JavaScript call change()
on website: "My website" (I know this is not valid, but this is what I want)
Also I would like to be able to change the different values and pass the function with parameters.
Thanks
Kristian
The website is here (Norwegian):
http://www.novasoftware.se/webviewer/(S(mfq2npum0th2lxb0g5oy3045))/design1.aspx?schoolid=60810&code=545354&type=3&id=1559)
Edit:
Hello I found another way to solve my problem.
The website is automatically generating an image for each of the students. The url of an image is similar to this link
(had some problems posting the URL)
Where you got &week=42
(you can change this to whatever you want and it works perfect). So I got it working for the MAC (in Safari 5).
But when I try to use this URL in the iPhone simulator I only get a white screen.
this is the code i use:
[webView loadRequest:[NSURLRequest
requestWithURL:[NSURL
URLWithString:@"http://www.novasoftware.se/ImgGen/schedulegenerator.aspx?format=png&schoolid=60810/nb-no&type=3&id={76C567C0-161E-42C3-B054-8941DDD04F52}&period=&week=42&mode=0&printer=0&colors=32&head=0&clock=0&foot=0&day=0&width=1405&height=683&maxwidth=1405&maxheight=683"]]];
It works if I use a simpler URL like "http://www.google.com" :S Does the iPhone not support for aspx?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只在 iPhone API 的上下文中知道这一点...
假设您已将页面加载到应用程序内的 UIWebView 中...
您可以调用
UIWebView
方法stringByEvaluatingJavaScriptFromString:
来将 javascript 发送到页面。如果调用函数返回任何内容,它将被类型转换为 NSString 并返回到您的应用程序,但在您的情况下,您似乎可以忽略返回值。您可能需要使您的 Javascript 看起来像:
因为我不确定它处理 void 返回值的效果如何。
I only know this in the context of iPhone APIs...
Assuming you have the page loaded in a UIWebView inside your app...
You can call
UIWebView
methodstringByEvaluatingJavaScriptFromString:
to send javascript to the page.If the calling function returns anything, it will be typecast as a NSString and returned to your app, but in your case it looks like you can just ignore the return value. You might need to make your Javascript look something like:
because I'm not sure how well it handles void return values.