Home  >  Article  >  Backend Development  >  JS如何获取iframe当前的url

JS如何获取iframe当前的url

PHPz
PHPzOriginal
2016-06-06 20:15:347070browse

JS获取iframe当前的url的方法:可以通过【parent.document.getElementById("iframe_id").contentWindow.location.href】来获取。

JS如何获取iframe当前的url

JS如何获取iframe当前的url?

在许多时候我们在用iframe的时候都会做分页操作,iframe内部的url跳转将不能直接通过iframe的src属性来获得

iframe的当前url的获取方法

parent.document.getElementById("content_info").contentWindow.location.href

其中:content_info为iframe的id

具体示例:

/**获取iframe 的当前url
 * @param {Object} id iframe的id
 */
function getIframUrl(id){
	var url = parent.document.getElementById(id).contentWindow.location.href;
	return url;
}

推荐教程:javascript视频教程

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn