![](/img/trans.png)
[英]javascript window.location iframe, make parent window go to location
[英]window.location prevent iframe from redirecting parent window
因此,我嘗試了多種方法來將我加載到iframe中的內容自動重定向到我的一個頁面上,並且它們似乎總是觸發父窗口重新加載/重定向,而不是將iframe定向到所需位置。
我知道大多數人都希望在iframe中完成任務時遇到相反的情況,他們希望重新加載父窗口或將其定向到其他地方。 但是在這種情況下,我希望我的腳本繼續到另一個頁面。
是否有內置機制不允許iframe自身重定向?
為了讓它假裝代碼是
if(someAction === true) {
window.location = '/some/new/path/index_new.html?param=something';
}
我也用window.top.location
和window.parent.location
嘗試,我認為還有其他一些隨機變體。 包括將.href
附加到每個變量的末尾。 毫無疑問,iframe的父窗口似乎總是在重定向,而不是希望的實際iframe本身。
iframe是一個簡單的iframe
<iframe src="/original/path/index.html"></iframe>
將要重定向iframe的腳本嵌入在/original/path/index.html中
就在這里。 請發布您的代碼或代碼段,以便我們了解您正在使用的代碼。 我為網站使用了iframe,該網站在同一框架內從父頁面打開了三個不同的頁面,並使用cookie來回處理數據。 但是,請顯示一些html div和js,以便我們了解您希望它如何工作。 這是我工作的一些代碼。 我使用本地存儲
function Redirect($page) {
localStorage.setItem('page',$page);
window.location="validateorder.htm";
}
function orderValidate($page) {
localStorage.setItem('page',$page);
$arr = $('iframe').contents().find('form').serializeArray();
$.each($arr,function(i,v){
createCookie(i,v);
});
window.location="ordersummary.htm";
}
$(document).ready(function(){
$('iframe').load(function() {
$page = localStorage.getItem('page');
$subtotal = localStorage.getItem('subtotal');
$tax = localStorage.getItem('tax');
$total = localStorage.getItem('total');
$table = $('iframe').contents().find('td#optionsPrice');
$form = $('iframe').contents().find('#frmContact');
$theform = $('iframe').contents().find('#theform');
if($table.length > 0){
$('iframe').contents().find('td#optionsPrice').text($subtotal);
$('iframe').contents().find('td#tax').text($tax);
$('iframe').contents().find('td#totalPrice').text($total);
}
if($form.length > 0){
$form.find('input').each(function(){
$name = $(this).attr('name');
$type = $(this).attr('type');
if($type != 'button'){
$(this).val(readCookie($name));
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.