Ryan
Ryan

Reputation: 2503

Automatically open external links with iframe?

I am working on a WordPress site that has a lot of authors. The stories often contain external links, and I am looking for a way that we can automatically have external links open with a small header that has a "Back to our site" link, along with a close button.

Ideally this would be done automatically, but we'd also like to be able to create links manually that open in this same sort of iframe with our header. How can I go about setting this up?

Upvotes: 1

Views: 4666

Answers (1)

fedmich
fedmich

Reputation: 5381

I suggest you build this via Javascript, so you could easily turn it off/on as needed and it will be kind of portable too and you can use it on other site as well.

steps to do: Go through all the anchor links and if the href is external link, add attribute target blank, and change the href links

 if(external_link){
   a.target = '_blank';
   a.href="http://example-ownsite.com/iframe_holder/?page="  + a.href;
 }

Then take a look at my page on http://fedmich.com/works/odesk/ so you could provide a vertical scrollbar on the iframed page. Im using a function called resizeIframe() there

Note: some sites dont want to be placed inside iframe and they will breakaway from the topframe.

Upvotes: 1

Related Questions