Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!