You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Google Sites设置iframe参数allow-modals?解决脚本弹窗打印失效问题

Fixing alert()/print() Failure in Google Script iFrames Embedded in Updated Google Sites

Hey there, let's get this sorted out for you. That sandbox error message you're seeing tells us exactly what's going on: Google Sites applies strict sandboxing to embedded iframes by default, and it's missing the allow-modals permission needed for alert boxes and print dialogs to work. Here's how to fix it step by step:

Step 1: Edit Your Google Sites Page

Open the Google Sites page where you've embedded the Google Script web app, and switch to Edit mode (click the pencil icon in the top right).

Step 2: Access the iFrame's Advanced Settings

  • Find the embedded iframe component on your page and click on it to select it.
  • Look for the More options menu (usually three vertical dots) in the component's toolbar, or click the Edit embed button that appears.
  • Navigate to the Advanced or Sandbox permissions section—this is where you can tweak the iframe's sandbox attributes.

Step 3: Enable the "Allow Modals" Permission

  • In the sandbox settings, you'll see a list of checkboxes for different permissions. Look for the option labeled Allow modals (it might be phrased slightly differently, but it corresponds to the allow-modals sandbox keyword).
  • Check that box—this adds allow-modals to the iframe's sandbox attribute, letting the browser permit alert() and print() calls from the embedded Google Script.

Step 4: Save and Test

  • Save your changes to the Google Sites page (click the Publish button if prompted).
  • Refresh the page and test your Google Script's alert() or print() functionality—they should now work as expected.

Quick Note About Google Script Web Apps

If your embedded content is a Google Script Web App, double-check its deployment settings to ensure it's accessible to the right audience (e.g., "Anyone, even anonymous" if your site is public). While this isn't directly related to the sandbox error, it can prevent other unexpected issues with the embed.

Ignored call to 'alert()'. The document is sandboxed, and the 'allow-modals' keyword is not set.

— Your browser's error message

This error occurs because modern browsers block modal interactions (like alerts or print dialogs) from sandboxed iframes unless explicitly allowed via the allow-modals keyword. Google Sites' default sandbox configuration omits this permission, so we have to manually enable it.

内容的提问来源于stack exchange,提问作者David DIVERRES

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 06:56:42