1

a little intro about what i need but cant find a complete answer anywhere. i use webbrowser control to show an website in my app, but i want to remove the above navigation which is alone in an html element with the class name "tabs-outer". i want to do this in my app and not in the css of the homepage, because it is made to show the content for mobile devices and i just want to display in my app in the webbrowser control without it and on desktop/mobile site that it remains visible like it is.

i found some java script codes like "$('#mydiv').allBut().hide();" i understand i must add something like "$('.tabs-outer').allBut().hide();" but where?! i have no clue, where to input this, how to call it in the app?! i need more info please. i found a thread that is 2 years old but no info about what exactly to do.

How and where to use this javascript, is it possible to add it in the app, so i call it in runtime this script?! any help? I am a newbie so i dont know anything about javascripts, and nothing about it from within windows phone and c#.

this is the way i use it now:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {

        String url = NavigationContext.QueryString["url"];
        if (!String.IsNullOrEmpty(url))
        {
           WebBrowser.Navigate(new Uri(url));
        }

    }
    private void WebBrowser_LoadCompleted(object sender, NavigationEventArgs e)
    {
        WebBrowser.InvokeScript("RemoveNav");
        SystemTray.SetProgressIndicator(this, null);
        WebBrowser.Visibility = Visibility.Visible;
    }

and i added a script on my webpage in the header like this:

<script type="text/javascript">
function RemoveNav() 
{ 
$('.tabs-outer').not(this).hide() 
}
</script>

and it works but, i must set the visibility of the webbrowser control to collapsed for the page to load - "hide" the element i want and then make is visible. but i need something to intercept the loading of this element, but only in my windows phone app in the webbrowser control.

dinchy87
  • 169
  • 1
  • 12

2 Answers2

1

You supplied jQuery source code. jQuery is open source and free to download and use. Please view this site for information about jQuery: http://learn.jquery.com/

Your exact answer is located and explained here: http://learn.jquery.com/using-jquery-core/document-ready/

Practically, after the page loads the code will run. Your necessary code is here:

<script>
// A $( document ).ready() block.
$( document ).ready(function() {
    $('.tabs-outer').hide();
});
</script>

You need to include this code in your webpage as a javascript. To use that code you also need to include the following line in the head section of your html page.

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>

This will load the jQuery plugin which will interpret your script and hide all the divs that have their class set to "tabs-outer".

Good luck!

George
  • 628
  • 6
  • 13
  • i have done it via this code $('.tabs-outer').allBut().hide(); and i call this script when the webbrowser is loaded but i still see the elements loading before the webbrowser control removes them... how can i "preload" this script and call it when the webbrowser control opens so i dont even see this element. – dinchy87 Sep 25 '13 at 01:58
  • You can do this in CSS, without having to use jQuery at all. I will provide a new answer in a moment. – George Sep 25 '13 at 02:10
  • thank you, but i can not imagine how to do it in css an to be visible only to my apps users... but i have done for now some little workaround, i have set the visibility of the webbrowser control to collapsed till the page is loaded, then to visible, so the part that the script "hides" is not visible, but for the user this means to wait for the whole page to load. – dinchy87 Sep 25 '13 at 02:23
  • Before applying my latest answer and providing me feedback, please remove the jquery import and script from your header. It's not needed and create overheat. Try the CSS solution and let me know how it does :-) – George Sep 25 '13 at 02:25
0

I have added this new answer because in some cases and for some users my previous answer will be suffice.

This problem can be solved with CSS. You load the page from a mobile device app and have access to the header section. With this in mind, you can set the div's style from there.

Using !important will override other specifications, but if the css already uses !important (I highly doubt it), you have to make sure your style is located after the page style. With this in mind, try adding the following code in the head element:

<style>
    .tabs-outer {
        display: none !important;
    }
</style>

This will completely remove your div.

UPDATE: Hide them for all devices and show them for non-wp

Step 1: Add the style in your header section

<style>
    .tabs-outer {
        display: none;
    }
</style>

Step 2: Add the import in the header section for the jQuery API

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>

Step 3: Add the code in your header

<script type="text/javascript">
$(document).ready(function(){
    if(!navigator.userAgent.match(/IEMobile/i) && !navigator.userAgent.match(/Windows Phone/i)){
        $(".tabs-outer").show();
    }
});
</script>

That's it. Desktop is faster so it should load the elements and show them fast enough.

**UPDATE: Use Media Queries and !important in CSS to hide what you need and customize the display

You can add the following code in CSS to solve the problem in the most efficient way:

@media only screen
and (min-device-width : 160px)
and (max-device-width : 640px) {
    .tabs-outer {
        display: none !important;
    }
    html {
        font-family : "Palatino Linotype";
        font-size : 12;
        font-color : #98AFC7;
    }

    .........

}

Resource: http://css-tricks.com/snippets/css/media-queries-for-standard-devices/

You can keep your custom style now. Sorry I didn't get it the first time, but it's been ages since I've worked on a website.

Please provide feedback. Again :-)

George
  • 628
  • 6
  • 13
  • i know that i can remove it this way, but this way it is removes also for the desktop users, and also for the mobile device users. i needed this script to use it in my windows phone app, in the webbrowser control. so i can not trigger this above from within the app?! – dinchy87 Sep 25 '13 at 02:26
  • but your first post helped me to remove it but it is slow because it loads the page and then hides, i would like to have this script available before the page loads so i call it with the webbrowser control so the page renders and the div is not rendered. is this possible? – dinchy87 Sep 25 '13 at 02:28
  • Wait. As I understood, you added the jQuery code in the windowsphone application. So I am telling you to replace the jQuery script with this CSS styling and this will solve it. Do you not have access to the head section on the windowsphone app? – George Sep 25 '13 at 02:30
  • oh you mean i should ad this in the app? on the page where the webbrowser control is or where?! – dinchy87 Sep 25 '13 at 02:31
  • i really dont know where to input this now because in my app on the xaml page where the webbrowser control is i can not add it anywhere because "style" is not in in any namespace of my app. – dinchy87 Sep 25 '13 at 02:38
  • please edit the question and provide some c# code so I can see what you are using – George Sep 25 '13 at 02:39
  • and to answer your question above about the script, i added it to the head section of my webpage, but i call it from the windows phone app and it works, but i want to hide the element before it is loaded, but only in the windows phone app, your css will change it for all users (desktop, iphone, android, all). – dinchy87 Sep 25 '13 at 02:40
  • can you use WebBrowser.InvokeScript("RemoveNav") before the webBrowser has finished loading? I.e. while it is loading? – George Sep 25 '13 at 02:48
  • no, then i have an exception, i tried it now with the navigating handler of the webbrowser but still an exception. i think i have read sometime that scripts can only be called when the page is finished loaded – dinchy87 Sep 25 '13 at 02:49
  • i have maybe and idea, can i load a local .jc file in my app, so i dont load it with the page and then maybe i can call it with the webbrowser in the same time?! it is possible to store scripts local in windows phone app? – dinchy87 Sep 25 '13 at 03:12
  • That was the solution I tried to give you a few comments up, but it seems that won't help you eighter. I updated my solution with some source code that you should add in the head section of your website and then test on the mobile device. This should be the solution. Finally! – George Sep 25 '13 at 03:20
  • Update: Tested the solution and included it in this answer. For me it seems to work fine, but I don't have the overheat from the page loading. – George Sep 25 '13 at 04:05
  • it says now that this script has an error on match(/IEMobile/i) && !navigator. it says the && is something wrong, and i can not save the template of my page... this is the error i get "The entity name must immediately follow the '&' in the entity reference" – dinchy87 Sep 25 '13 at 20:50
  • i deleted now this section "!navigator.userAgent.match(/IEMobile/i) &&" an leave only the windows phone useragent match and it works. your are a genius :) but there is always an but, if i go with internet explorer on my main page how can i only show there .tabs-outer and on article page not, so far my page is wpnovosti.com all the article pages where it have some endings like wpnovosti.com/2013/09/bla bla bla bla.html can i somehow configure this script to show tabs-outer on the mainpage, but on all other not?! – dinchy87 Sep 25 '13 at 21:15
  • second update now - in internet explorer of windows phone it works, but in my app where i use webbrowser control it still shows the elements that should be hidden :S – dinchy87 Sep 25 '13 at 21:29
  • Well, if you continue to go in this direction, you need to find out what your webbrowser's name is so you can add that to the javascript. [This link] (http://stackoverflow.com/questions/11219582/how-to-detect-my-browser-version-and-operating-system-using-javascript) will provide source code that you can add to a page on your website and open that page only in the webbrowser. This would provide you all the info you need to make the code work perfectly :-) – George Sep 25 '13 at 22:48
  • Personally, I think this solution (to open in webbrowser and strip the page) caused more overheat than needed and it might impact user experience on your website. Because of this, I strongly recommend you make a new php file on your website that gives you only the needed article or page with comments and all and access that page only with the webbrowser. Do you think this will work best for you? – George Sep 25 '13 at 22:50
  • yes but how is this made, and access via windows phone app?! i use webclient to download this feeds from my site and i use selection changed event on th elist box where the feeds are populated to get the url fro mthe particular feed item, and then i pass it further on this page where this webbrowser control is. it would be better to have only thing i want in the webbrowser control... but i am a newbie :( – dinchy87 Sep 25 '13 at 23:05
  • I presume you download this feeds from the site only from the WP Application? If this is true, then simply create a new php version of your current index file and save it index_wp.php. Then in your WP app instead of going for index.php?attr=x&attr2=y go for index_wp.php?attr=x&attr2=y. In addition, I see you use mor_rewrite on your website. It's been years since I've worked with that, but I do know that you will have to add a new rewrite rule for index_wp.php. The (LINK)[http://www.sitepoint.com/guide-url-rewriting-2/] will help you with that. Tell me if this works for you? – George Sep 25 '13 at 23:23
  • this is an good answer and i know what you mean, a seperate version of my site, i have done this via css and "media screens" i set my page to the witdh of 320 wich is the width of the webbrowser control and it shows ok, changed some elements, font size and so on and its ok. but i used only width of the device in media i wish there would be a seperate thing like devices and different css for windows phone and so on. i ncss i could easily change it not to show it and on desktop remain still visible, but i think this solution now is better with this script but on the webrowser control it is vis. – dinchy87 Sep 26 '13 at 00:14
  • It's fun because you tell me "what if" and I burst on remembering exactly what you need :) You can use media queries in CSS. The following link http://css-tricks.com/snippets/css/media-queries-for-standard-devices/ will offer you exactly what you need. I will update my answer for a complete code sample (that should work). If the answer is useful don't hesitate to "UP" the answer :) – George Sep 26 '13 at 00:43
  • i wish i could up vote, even twice, because you helped me a lot but i have not enough point for now :( but i will for sure! i have found an solution because i use media queries already, like "@media screen and (max-width:480px) and (orientation: portrait)" and here i use this display: none on the tab-outer element but i use then the script you send with the useragents.match only set to windows phone and it works :) – dinchy87 Sep 26 '13 at 00:50
  • Glad I've helped you out :-) happy coding – George Sep 26 '13 at 00:54