SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
-
Apr 7, 2007, 19:41 #1
- Join Date
- Apr 2002
- Posts
- 395
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Force target="_blank" on an iframed page
I have an iframed page on my website. The iframed page has links that have set target="_top" and so they open over my website.
I want all the links in the iframed page to open in a new window. Can I do that?
-
Apr 7, 2007, 19:54 #2
- Join Date
- Jul 2005
- Location
- West Springfield, Massachusetts
- Posts
- 17,290
- Mentioned
- 198 Post(s)
- Tagged
- 3 Thread(s)
target
Originally Posted by IamAdam
Big Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
-
Apr 8, 2007, 16:39 #3
- Join Date
- Apr 2002
- Posts
- 395
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No, the thing is, the page I am framing is not mine - I don't have control over it.
-
Apr 8, 2007, 19:51 #4
- Join Date
- Jul 2005
- Location
- West Springfield, Massachusetts
- Posts
- 17,290
- Mentioned
- 198 Post(s)
- Tagged
- 3 Thread(s)
target attributes
I see. Then I guess you should explain your problem to the page's author and ask them if they would remove them. I can't think of a reason why they shouldn't as long as you can explain yourself clearly enough.
Big Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
-
Apr 9, 2007, 02:32 #5
- Join Date
- Mar 2007
- Location
- Germany
- Posts
- 428
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Perhaps this may work - I adapted it a little, normally I used this to mak links opening in a new window without the target-attribute hardcoded - instead I used rel="external" and set the target with JS.
Try it and let me know if itworks
Code:function externalLinks() { if(!document.getElementsByTagName) { return false; } var anchors = document.getElementsByTagName("a"); for(var i = 0; i < anchors.length; i++) { var anchor = anchors[i]; if (anchor.getAttribute('href') && anchor.getAttribute('target') && anchor.getAttribute('target') == '_top') { anchor.target = '_blank'; } } } window.onload = externalLinks;
-
Apr 18, 2007, 09:51 #6
- Join Date
- Apr 2002
- Posts
- 395
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for the code, and sorry for my belated reply.
The page in the iframe does not actually have hardcoded target. The iframed page contains javascript links which are set to open in "_top"
However, there is nothing on the iframed page that has target="_top". Only javascript which contains links that open in "_top"
To make this look more imaginable, I am framing a javascript adcode.
-
Apr 18, 2007, 13:10 #7
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
You can't use javascript to update a web page from another site that is displayed in an iframe. Whatever is in the iframe works the way the owner of that page intends it to. In the case of ads, making any such change would violate the terms of service for your ad account if this were possible.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
Bookmarks