简体   繁体   English

如何将哈希附加到UIWebView位置href?

[英]How can I append a hash to a UIWebView location href?

I have iPad application where I load a local html into a UIWebView. 我有iPad应用程序,我在其中将本地HTML加载到UIWebView中。 How can I append a hash tag to the URL, so that the hash tag to the web view href so that it is there from start? 如何将哈希标签附加到URL,以便将哈希标签添加到Web视图href,以便从一开始就存在?

What I want to do is: 我想做的是:

  1. Load the html page from local file 从本地文件加载HTML页面
  2. Append a hash tag to the UIWebview href 将井号标签附加到UIWebview href
  3. Inject the html into the web view 将html注入Web视图
  4. Display the page 显示页面

1) Use UIWebView's loadHTMLString:baseURL: method. 1)使用UIWebView的loadHTMLString:baseURL:方法。 See past posting for details 详细信息请参阅过去的帖子

2) I presume the hash tag is used in step 4, if not provide further details why its at step 2 but you don't display the page until step 4. You can do this using Javascript. 2)我假设在步骤4中使用了hash标签,如果没有提供为什么在步骤2中使用它的更多详细信息,但是直到第4步您才显示该页面。您可以使用Javascript进行此操作。

3) You need to execute Javascript which will alter the dom. 3)您需要执行Javascript才能更改dom。

4) Again using Javascript, do a location change. 4)再次使用Javascript,进行位置更改。 If you load the page again using loadHTMLString:baseURL you'll just get the original page again. 如果您使用loadHTMLString:baseURL再次加载页面,您将再次获得原始页面。

So you need to do a lot of execution of Javascript, the method to do that is UIWebView's stringByEvaluatingJavaScriptFromString:. 因此,您需要执行很多Javascript,执行方法是UIWebView的stringByEvaluatingJavaScriptFromString:。 See past postings for details. 有关详细信息,请参阅过去的帖子。 If you're loading the page to jump to the hash tag then just add the hash tag here and not in a separate step 2. 如果您要加载页面以跳转至哈希标签,则只需在此处添加哈希标签即可,而不是在单独的步骤2中进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM