![](/img/trans.png)
[英]Is it possible to modify the page being loaded in the cross-domain <iframe>?
[英]Is it possible to modify an iframe contents in a classic ASP page after it has loaded
我有一个经典的ASP页面,它通过ASP页面内的iframe加载ASP.net页面。 这很有效,除了加载ASP.net页面需要一段时间。 用户留在这里有不愉快的经验,因为他们所说的只是一个空的空白页,直到页面完成加载。
我想要做的是加载一个初始的“加载”ASP.net页面,以便至少向用户显示一些东西,然后当ASP.net页面准备就绪时,将正确的ASP.net页面加载到iframe中。
这可能吗? 我想也许有点javascript但不是100%肯定。
您可以在加载页面后使用JQuery修改iframe。
stackoverflow上的另一个问题已经包含了一个很好的例子:
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function(){
var locations = ["http://webPage1.com", "http://webPage2.com"];
var len = array.length;
var iframe = $('#frame');
var i = 0;
setInterval(function () {
$iframe.attr('src', locations[++i % len]);
}, 30000);
});
</script>
一旦它到达浏览器就没有“ASP页面”,只有生成的HTML。
你有一些问题:
1)如果你在iframe中放了一些东西,一旦加载新页面就会覆盖它。 因此,您无法使用Iframe中的内容来显示您的消息。
2)如何判断iframe何时加载
您需要确定页面上Iframe的位置和大小。 您需要使用您的消息在其上放置一个元素。 修改绝对定位元素的样式以使用JavaScript覆盖Iframe。 大多数人会使用一个框架,比如jQuery,使它变得更容易。
然后,您需要检测Iframe何时加载并隐藏此元素。
您可以使用此代码确定Iframe已加载:
function checkIframeLoading() {
// Get a handle to the iframe element
var iframe = document.getElementById('testIframe');
// Check if loading is complete
if ( iframe.document.readyState == 'complete' ) {
// The loading is complete, call the function we want executed once the iframe is loaded
functionToCallAfterLoading();
return;
}
// If we are here, it is not loaded. Set things up so we check the status again in 100 milliseconds
window.setTimeout('checkIframeLoading();', 100);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.