Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
Opening blog entries that are loaded with iframe. Targeting different iframes with add on in URL

I have trouble describing my problem because I am still somewhat of a beginner in HTML and English is not my native language. Please bear with me.

I have a website that has somewhat of a blog. Each week I change out the iframe link to the content of just the blog, navigation and introduction stays the same.

<div class="blog"><iframe src="Blogs/REVblog20211023.html" name="myBlogFrame" scrolling="yes"></iframe</div>

Older entries are loaded in the same iframe window.

<a href="Blogs/REVblog20211002.html" target="myBlogFrame"><li>October 2nd<br /> <img src="blogs/Media/spacer.gif" width="100%" height="1px" alt=""/>What drives obesity?</li></a>

Is it possible to add something to the URL, so that an older blog is automatically opened?

Like this: https://reversing-insulin-resistance.com/blog.html?#iframe:Blogs/REVblog20211002.html

Obviously some code would have to be added to the website to make the automatic switch possible.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can. Basically on page load, you check if that bit is there and do something with it if it is. I'd use a query (?) instead of a hash (#) though, as hash is generally used for jumplinks that the browser can do automatically and you don't necessarily want to overload it. (You can if there is a specific reason to do so, it's just usually better to use a query instead.)

If you put your script as the last element in your body (and the HTML isn't dynamically created with JavaScript), that should be sufficient.

If you use a URL ending like this: ?iframe=path/to/older.html

Then, it's just be something like:

const domain = 'https://example.com';

// gives "iframe=path/to/older.html"
const query = location.search.slice(1); 

// in case you ever add more query params in the future, it's good
//  to process them properly
// this will give an array like [["iframe", "path/to/older.html"]]
const pairs = query.split('&').map(pair => pair.split('='));

// find just the iframe path
// if the query isn't there, iframePath will just be undefined
const [, iframePath] = pairs.find(([key]) => key === 'iframe') || [];

// if we got an iframePath, assign it as the URL of your iframe
if (iframePath) {
  document.querySelector('iframe').setAttribute('src', domain + '/' + iframePath);
}

And that should do the trick. If you have more than one iframe on the page, you'll want to adjust the document.querySelector() to a different selection to get the correct iframe. And obviously, set the domain properly.

If they happen to be the same domain as the page with the iframe, you could also just do location.origin or something instead of hard-coding it.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda