How would I check in javascript if web part zones have no web parts?
Thanks
You can check if a page has some webparts or not.
var siteUrl = '/sites/MySiteCollection';
var serverRelativeUrl = '/sites/MySiteCollection/Default.aspx';
function updateWebPartTitle() {
this.clientContext = new SP.ClientContext(siteUrl);
var oFile = clientContext.get_web().getFileByServerRelativeUrl(serverRelativeUrl);
var limitedWebPartManager = oFile.getLimitedWebPartManager(SP.WebParts.PersonalizationScope.shared);
this.collWebPart = limitedWebPartManager.get_webParts();
clientContext.load(collWebPart);
clientContext.executeQueryAsync(Function.createDelegate(this, this.SuccessFunc), Function.createDelegate(this, this.onQueryFailed));
}
function SuccessFunc() {
if (!collWebPart.get_count()) {
alert('No Web Parts on this page.');
}
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
Check MSDN source here.
Update:
If you know the webpartzone id and try something like this.
<div class="inner">
<WebPartPages:WebPartZone id="zone1"><ZoneTemplate></ZoneTemplate></WebpartPages:WebPartZone>
</div>
then query the zone and see it has table element because generally webpart will be rendered in a table.
if($('#zone1').find('table').length != 0){
//webpart exists
}
You may need to adjust your code based on actual dom.I can not test it now.