Links in the iframe to open in a new tab

I have seen this question many times, and many answers seem to offer the basic method target="_blank" . However, I have used this before in the past; but my current page is not working. I also don't think that this might be the best option, even if it works; since I ONLY want the links in iframe src="" open in a new window. I will download a simple solution there, which I can add to the line on the page. I also tried adding an identifier, as shown below, and using JavaScript is still nada.

 <iframe src="mywordpressfeed.html" id="frame1" width="310" height="380"></iframe> 

Js

 $(document).ready(function(){ $("#frame1").attr("target","_blank"); }); 

Basically the goal is when the user sees my wordpress channel inside the iframe, which I have on a static page; after clicking on the message header, it loads in a new window - since now it loads within the same iframe, so there is no increased level of readability.

+1
javascript jquery html html5
source share
2 answers

There is no real solution to this, because the iFrame tag is designed for the opposite.

+2
source share
 //pass the iframe to this iframe getting function function iframeRef( frameRef ) { return frameRef.contentWindow ? frameRef.contentWindow.document : frameRef.contentDocument } //Get Iframe var inside = iframeRef( document.getElementById('iframeID') ); //Get all links var links = inside.getElementsByTagName('a'); //Loop throught links and set their attributes for (var i = 0 ; i<links.length ; i++){ links[i].setAttribute('target','_blank'); } //No jQuery needed! 

thanks to the medium

EDIT Due to iframe restrictions associated with the source code, I had to find a website with an internal iframe from the same source so you can paste this code

 //pass the iframe to this iframe getting function function iframeRef( frameRef ) { return frameRef.contentWindow ? frameRef.contentWindow.document : frameRef.contentDocument } //Get Iframe var inside = iframeRef( document.getElementById('IFwinEdit_Gadget_247730_3349') ); //Get all links var links = inside.getElementsByTagName('input'); //Loop throught links and set their attributes for (var i = 0 ; i<links.length ; i++){ links[i].setAttribute('style','background:red'); } //No jQuery needed! 

to the console on this website and see how the inputs change color

+1
source share

All Articles