开发者

Calling an iframe

开发者 https://www.devze.com 2022-12-17 13:47 出处:网络
I created an index page with an iframe, calling srs files. The problem is that the src files are listed in Google etc. Clicking from Google on these \"src\" files does not load the开发者_JAVA百科 inde

I created an index page with an iframe, calling srs files. The problem is that the src files are listed in Google etc. Clicking from Google on these "src" files does not load the开发者_JAVA百科 index file, displaying the basic src file. Is there a way to overcome this?


This is a problem that was more common when a lot of sites used framesets. What you need is a script that detects if the page is opened as the main page, and redirect to the index page if it is, sending it's url along as querystring parameter:

if (window.location.href == window.top.location.href) window.top.location.href = 'index.html?url=' + escape(window.location.href);

In the index page you would have to detect the querystring that is sent to it, and load the page in the iframe:

var url = /url=(.+)/.exec(document.location.search);
if (url.length == 2) {
  document.getElementById('IdOfTheIframe').src = url[1];
}

You might consider to incorporate the information in the page instead of using an iframe, that is more common nowadays. If you can't do it on the server side, you could use AJAX to load content into the page.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号