最简单的方法是使用iframe
.
您可以使用仅包含Chatbot组件的页面托管您的Next.js应用程序,并将背景 colored颜色 设置为透明.
background-color : transparent;
然后,任何可以访问你的应用程序的人都可以使用iframe
将聊天机器人嵌入到他们自己的网站中.加allowtransparency="true"
会达到你想要的效果.
<iframe src="https://your-nextjs-app/chatbot-page" allowtransparency="true"></iframe>
IFRAME上的more info%允许透明.
要使用Java脚本创建iFrame,请执行以下操作:
// Create the iframe element
var iframe = document.createElement('iframe');
// Set the iframe attributes
iframe.src = 'https://your-nextjs-app/chatbot-page';
iframe.style.position = 'fixed';
iframe.style.bottom = '0';
iframe.style.right = '0';
iframe.style.width = '400px';
iframe.style.height = '600px';
iframe.style.border = 'none';
iframe.style.opacity = '0.5';
iframe.style.zIndex = '9999';
iframe.allowtransparency = true;
iframe.style.backgroundColor = 'transparent';
// Append the iframe to the document body
document.body.appendChild(iframe);