简体   繁体   中英

Hide both div and javascript code on mobile device

I Have two Divs apart from my content in my Bootstrap Layout

a) Social networking bar div

<div id="socialnetwork" class="navbar-text navbar-right visible-md visible-lg">
<span class='st_googleplus_large' displayText='Google +'></span>
<span class='st_plusone_large' displayText='Google +1'></span>
<span class='st_facebook_large' displayText='Facebook'></span>
<span class='st_fblike_large fblike-align' displayText='Facebook Like'></span>
<span class='st_twitter_large' displayText='Tweet'></span>
<span class='st_email_large' displayText='Email'></span>
</div>

Associated JS Embed Tag

<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js">
</script>
<script type="text/javascript">
stLight.options(
{publisher: "f1325bca-f8fc-4cec-9e01-02cd5ddd29ed", 
doNotHash: false, doNotCopy: false, hashAddressBar: false}
);
</script>

b) Disqus Comments Div

<div id="disqus_thread" class="col-lg-10 visible-md visible-lg"></div>

Screenshot Example - http://tinypics.in/image/o Jsfiddle code Example - http://jsfiddle.net/betacoder/buC6c/

My Aim is to ONLY LOAD this DIV along with there associated JAVASCRIPT if the viewport is for midscreen or largescreen and not on mobile / tablet layout (tohide if mobile/tablet)

Well the " visible-md visible-lg " tags lets me to hide the divs in mobile and tablet layouts.

But still the javascript is loading in the background and consuming the user bandwith.

How to resolve this , would like to load the JS files associated with them only when Bootstrap layout on medium and large screen or on devices above 990px width.

Any Quickfix ? Love to hear the response or a near workaround.

Welcome to StackOverflow! Even though the markup is hidden, it is still delivered to the browser, just like the JavaScript. You will not be able to prevent JavaScript from loading using only CSS rules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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