1

I have a project on the way but I can't seem to add javascript support to this method, any insight? I didn't include the line in the code because I tried it in every way possible, and even when it wouldn't error it would still not load Js support.

@Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);

            rootView.setTag(getArguments().getInt(ID)); //define the rootView with an id Tab in order to be accessed later from inside the menu button

            swipeRefreshWeb = rootView.findViewById(R.id.swipeRefreshWeb);
            swipeRefreshWeb.setOnRefreshListener(this);

            //GET THE WEBVIEW FROM THE XML LAYOUT
            webView = rootView.findViewById(R.id.section_web_view);
            webView.setWebViewClient(new WebViewClient() { //NEEDED TO CREATE IN ORDER TO OPEN SOME WEBPAGES INSIDE THE APP AND NOT BY OPENING THE CHROME APP
                public void onReceivedError(WebView view, int errorCode, String description, String   failingUrl) {
                    Toast.makeText(getContext(), description, Toast.LENGTH_SHORT).show();
                }
            });
            webView.loadUrl(getArguments().getString(URL)); //load the url

            rootView.findViewById(R.id.btnWebBack).setOnClickListener(new View.OnClickListener() { //Define the Back click button
                @Override
                public void onClick(View view) {
                    webView.goBack();  //go back when the back button is clicked
                }
            });
            return rootView;
        }
  • If you're asking about WebView, try `WEBVIEW.getSettings().setJavaScriptEnabled(true);` – FrozenFire Jul 29 '17 at 02:37
  • @FrozenFire I was a bit confused, I added JS, but twitter still wont show up as "desktop/pc" version, and switches to Mobile in webview. – Edward Benedict Jul 29 '17 at 02:55
  • I think JS does nothing with Mobile view, it's just CSS is designed as mobile responsive. Unless JS is designed to redirect mobile user to different URL. – FrozenFire Jul 29 '17 at 03:01
  • @FrozenFire From what I know, when I did regular webview with no fragments i was able to get the desktop version of Twitter. – Edward Benedict Jul 29 '17 at 03:18
  • Fragment has no relation with webview. It's all depends on the Webmaster(s) of Twitter or whatever sites, to decide how they will handle mobile users. Such mobile responsive approach is done with CSS, JS redirects, or Server side scripts (PHP, ASP, etc.). For now, you may try fooling the Twitter with fake User-agent. See this post https://stackoverflow.com/questions/14688030/setting-webview-to-view-desktop-site-and-not-mobile-site – FrozenFire Jul 29 '17 at 03:28

0 Answers0