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

女生的网名这么多〃 提交于 2019-12-04 09:51:37

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.

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

<base target="_parent">

in the head.

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