Xcoder
Xcoder

Reputation: 199

Removing website content using HTML (Xcode)

This is a very hard question, for all of you. Maybe some of you can answer it and if you do you are a life saver. Ok so my project is an RSS Feed which displays the news and when you click on it, it takes you to the page of the article. The website I am getting this feed from has menu and the user HAS to scroll down each time to view the full article. :(

So I know in WebView you can embed code into the web view, I was wondering if there was some code in HTML of how you can actually delete this menu. I add some screen shots. Look :

enter image description here

It is a Wordpress website, if you could give me the HTML code it would be awesome but it would be even better if you can give me the Xcode code to do this as well.

Thanks to everyone that takes the time to read / reply.

Upvotes: 0

Views: 417

Answers (2)

Guillaume Algis
Guillaume Algis

Reputation: 11016

Use css to hide the menu:

#nav_menu-2 {
    display: none;
}

In your context, you can automatically apply this change by injecting a Javascript script in your webview, which will apply the css rule to your element:

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    NSString *js = @"document.getElementById('nav_menu-2').style.display = 'none';";
    [self.webView stringByEvaluatingJavaScriptFromString:js];
}

However, this is far from perfect as the js snippet will be executed after the page has finished loading, so the user will see the menu disappear.

EDIT:

If you don't want to reference the div's id, you could use the class widget_nav_menu:

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    NSString *js = @"var menus = document.getElementsByClassName('widget_nav_menu');"
        "for (var i = 0; i < menus.length; i++) {"
        "menus[i].style.display = 'none';"
        "}";
    [self.webView stringByEvaluatingJavaScriptFromString:js];
}

Beware that this will hide all elements with this class (but this could be what you need).

Upvotes: 2

MikeeeG
MikeeeG

Reputation: 341

Can you supply a link or the html for the menu?

A frontend solution would be to use javascript/jQuery with something like:

<script>
    $(document).ready(function(){
        $('#your-menu-id').hide();
    });
</script>

Upvotes: 1

Related Questions