重新加载iFrame,等到它加载,在同一个iFrame中打开URL

so when it comes to Javascript, I have no idea what I am doing.

I have a main page, with two iFrames. The main "content" iFrame holds the main content, in this case, the results from a MySQL database SELECT. The bottom iFrame is used to add rows to the same table.

When the 'add row' form is submitted from the bottom iFrame, I want the 'content' iFrame to load the list of results, and scroll to the newly added result.

I use

Currently, the only way to make this work that I have found is echo-ing the following code once upon successful row entry:

parent.document.getElementById('content').contentWindow.location.reload();
parent.document.getElementById('content').src = '../pages/results.php#".$id."';

The $id variable is set with $mysqli->insert_id;

The above code works, but it's obviously bad coding, on slower connections, for example, I can imagine the browser will fail to change the src as the reload action is still performing.

So, what can I add to my code, or what can I change my code to, to make the javascript either:

  1. Reload the 'content' iFrame to show the new row and then navigate to the anchor to scroll the user to the newly created row. or

  2. Do all of that in one simple action (I've found just using the bottom line of the two lines on it's own doesn't work, so the reload seems necessary to me at the moment.)

dtjo87679
dtjo87679 你可以尝试一下:pastebin.com/eEykZxyT。
大约 5 年之前 回复
dtest84004
dtest84004 或者让您的JS在更改源之前等待第一次重新加载的onReady事件。
大约 5 年之前 回复
drcb19700
drcb19700 可以使用Ajax将数据发布到数据库中,然后将新内容附加到当前列表中。然后没有刷新或重新加载。
大约 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐