简体   繁体   中英

How to re-load a web page when window is resized and only if it contains a particular HTML element

I want to add a jQuery statement to my website so that, if a user re-sizes the browser window, the web page is re-loaded but ONLY if that page also contains an HTML (DIV) element with a class of ".bx-slider".

I think I need to wrap an IF statement around the following but I would really appreciate some help on how to do this:

$(window).bind('resize',function(){ 
     window.location.href = window.location.href; 
});

You just need to check the element exists then do you what you want.

$(window).resize(function(){ 
     if( $('.bx-slider').length ) {
          location.reload();
     }
});

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