jQuery onload里面的iframe内容相同

时间:2015-06-24 14:30:36

标签: javascript jquery html iframe

我想在加载iframe中的div,div加载时触发一个函数,而不仅仅是iframe,因为在我的情况下加载iframe时会触发jquery ajax调用来加载该div中的数据,所以我有两个步骤:第一步加载iframe(我可以在此步骤中触发一个函数),在ajax回调后加载第二步div(我不能在此步骤中触发一个函数)。

相同的原始政策没有问题,因为iframe位于同一网站内。

感谢。

1 个答案:

答案 0 :(得分:0)

您可以从dispatch功能event iFrame parent callback postMessage window.addEventListener('message', receiveMessage, false) function receiveMessage(e){ //whatever needs to happen } window.top.postMessage('div loaded', yourDomain) 可用于窗口通信。 像这样:

在父窗口中:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/myToolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:titleTextAppearance="@style/ToolbarTitleAppearance"
    app:subtitleTextAppearance="@style/ToolbarSubtitleAppearance"
    android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>

在你的iFrame中:

<style name="ToolbarTitleAppearance" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title">
    <item name="android:textSize">20dp</item>
    <!-- include other attributes you want to change: textColor, textStyle, etc -->
</style>

<style name="ToolbarSubtitleAppearance" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle">
    <item name="android:textSize">14dp</item>
</style>