Search code examples
phpjqueryajaxiframeiframe-resizer

Refer to a particular TAG in url via IFRAME - jQuery/PHP


I'd like to know if i can refer to a particular tag (in our example H1) via the link directed (Src) in an Iframe.

For the example the link http://www.marketwatch.com/story/what-the-fed-raising-rates-would-mean-for-your-credit-cards-and-bank-accounts-2016-12-14

I'd like to know if i can refer to a the first H1 in the link below ("How the Fed rate hike will impact millions of Americans") The main goal is to see the Article directly.

<iframe id="iFrame1" scrolling="no" src="http://www.marketwatch.com/story/what-the-fed-raising-rates-would-mean-for-your-credit-cards-and-bank-accounts-2016-12-14#H1" style="overflow: scroll; -webkit-overflow-scrolling: touch;" sandbox=""></iframe>
  • What do i mean by 'refer to the h1 tag'? I mean that I want to scroll the iframe down to that element.
  • The idea is to directly to a specific TAG (H1ׂ) without ID or CLASS (At All articles in all the world sites have only one H1).

Solution

  • Assuming that you mean you want the iframe to scroll down to the h1 tag you can add a fragment to the URL which matches the id attribute of the required element. In this case it's #article-headline. Try this:

    <iframe id="iFrame1" scrolling="no" src="http://www.marketwatch.com/story/what-the-fed-raising-rates-would-mean-for-your-credit-cards-and-bank-accounts-2016-12-14#article-headline" style="overflow: scroll; -webkit-overflow-scrolling: touch;" sandbox=""></iframe>