Skip to main content

TossAds.destroyAll

Destroys all banner ad slots currently on the page, removing them from the DOM and releasing their resources. Use this for bulk cleanup on page transitions or component unmounts.

Signature

destroyAll is exposed as a member of the TossAds namespace object.

import { TossAds } from '@apps-in-toss/web-framework';

declare const TossAds: {
destroyAll: (() => void) & {
isSupported: () => boolean;
};
};

Parameters

None.

Returns

  • void — no return value.

Permission

No permission required — TossAds.destroyAll is not bound to a PermissionName. For the typical permission flow used by other namespaces, see Guides — Permissions pattern.

Examples

Minimal

import { TossAds } from '@apps-in-toss/web-framework';

TossAds.destroyAll();

Realistic — clean up all ad slots on page unmount

import { TossAds } from '@apps-in-toss/web-framework';
import { useEffect, useRef } from 'react';

const AD_GROUP_ID = 'ad-group-id-here';

function AdsPage() {
const bannerRef = useRef<HTMLDivElement>(null);

useEffect(() => {
if (!bannerRef.current) return;
if (!TossAds.initialize.isSupported()) return;

TossAds.initialize({});
TossAds.attachBanner(AD_GROUP_ID, bannerRef.current);

// Destroy all slots when the page unmounts
return () => {
TossAds.destroyAll();
};
}, []);

return <div ref={bannerRef} />;
}

Try it live

Open the Ads page in sdk-example and run the TossAds.destroyAll card to inspect the result.

Open in sdk-example

External references