Change target of all links inside an iframe to “_parent” jquery

孤街醉人 提交于 2019-12-06 04:05:55

问题


im trying to set the target to all links inside an iframe to "_parent" using jquery but im not sure how to do it, can anyone help me?

<script src="jquery-1.5.2.min.js">
$('a').target("_parent");
</script>  

<iframe src="http://google.com" frameborder="0"></iframe>

Im doing this because I want to customize my firefox 4 homepage to show me the Google's start page with the restore session button near the "Sign in" link, and I almost do it but i don't wanna open the new links or searches inside the iframe.

Thanks

P.S. If is there another way without using jquery it would be great.


回答1:


It's

$('a').attr("target", "_parent");

There's no method in jQuery called target() ;) Read about the attr method in jQuery - http://api.jquery.com/attr/

To go along with that, you should have the two <script /> tags separate.

<script src="jquery-1.5.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$('a').attr("target", "_parent");
</script>

And just so you know, you cannot access the content of an iframe if its content is hosted on a different domain than its parent document.




回答2:


It might be noted that you could do this without scripting anything with a base tag

<base target="_parent">

in the head.



来源:https://stackoverflow.com/questions/5608781/change-target-of-all-links-inside-an-iframe-to-parent-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!