开发者

Opening links that are in an iFrame(no control over the child site) in the parent window

I am making an app for a website, and I need to include a certain part of the website, which I have done with an iframe. I have turned that into my own site, and everything works fine with the web view and such. The problem is the links are opened inside the iframe, whereas I want the pa开发者_运维百科ge to fill the web view. I cannot modify the links themselves, as they are not on my site; only the script is.

I have tried inserting target="_top", blank, and parent, but nothing seems to be working. Here is a snippet of the HTML I am using. (I have changed the URL, by the way.)

How should I go about fixing this? Should it be fixed through Xcode, or through the script?

<html>
 <head>
  <title>
  </title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

     <style type="text/css">
     #container{
     width:380px;
     height:4300px;
     border:0px solid #000; 
     overflow:hidden;
     margin:auto;
     border:none;
     }
     #container iframe {
     width:380px;
     height:4880px;
     margin-left:-6px;
     margin-top:-398px;   
     border:none;
     }
   </style>
  </head>
 <body>
  <div id="container">
   <iframe src="http://www.Google.com/" scrolling="no">
   </iframe>
  </div>
 </body>
</html>


I think jQuery can help you. You need to find all links inside your frame and add required attribute to each of them.

$('#yourIframe').contents().find('a').each(function () {
    $(this).attr('target', '_blank');
});

P.S. Don't forget to change your ifarame id (or change to class, if you like).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜