Skip to content

Can we modify the rendering if displayed into an iframe ? #4674

Closed Answered by brc-dd
nicolas-bastien asked this question in Q&A
Discussion options

You must be logged in to vote

You can do something like this:

// .vitepress/config.ts

import { defineConfig } from 'vitepress'

export default defineConfig({
  head: [
    [
      'script',
      { id: 'check-iframe' },
      `window.self !== window.top && document.documentElement.classList.add('iframe')`
    ]
  ]
})

And add this to styles:

.iframe header {
  display: none !important;
}

/* ... for footer, etc. similarly. override any padding, etc. too if needed */

For chat widget, I'm not sure what your code looks like, but probably you can conditionally initialize that? Or you can hide it from CSS too.

BTW very clean site.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@nicolas-bastien
Comment options

@brc-dd
Comment options

@nicolas-bastien
Comment options

@mathieu-ducrot
Comment options

Answer selected by brc-dd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants