Capturar web actual de un iframe
Publicado por jorge (3 intervenciones) el 27/12/2017 17:42:38
Hola a todos:
Estoy tratando de encontrar la forma de capturar la url que actualemtne está mostrando un iframe que tengo dentro de una pagina .html.
El código que he desarrollado hasta el momento, es el siguiente:
Vean que en la funcion "getSrc" he realizado todo tipo de pruebas guiándome por los métodos/propiedades que aparecen colgados del iframe cuando le das al F12 rn firefox.
Lo que necesito es capturar la url completa (lo mismo que se almacena en el historial de navegación)
¿Alguien me puede ayudar?
Un saludo
Estoy tratando de encontrar la forma de capturar la url que actualemtne está mostrando un iframe que tengo dentro de una pagina .html.
El código que he desarrollado hasta el momento, es el siguiente:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<html>
<head>
<script type="text/javascript">
<!--
function setSrc(obj, url) {
obj.src = url;
}
function getSrc(obj) {
alert("01 - " + obj.src);
//alert("02 - " + obj.contentWindow.location);
//alert("03 - " + window.iframes[0].location.href);
//alert("04 - " + window[0].object);
//alert("05 - " + obj.allowFullscreen);
//alert("06 - " + obj.contentWindow.object);
//alert("07 - " + obj.contentWindow.document.location.href);
var x = document.getElementById("myframe")[0].contentWindow;
//var y = (x.contentWindow || x.contentDocument);
//var x = document.getElementsByTagName("iframe")[0].contentWindow;
alert(x);
//alert(y.location);
//alert(y.location.href);
// // // var x = document.getElementById("myframe");
// // // var y = x.contentWindow.document;
// // // y.body.style.backgroundColor = "red";
// // //
return obj.src;
}
//-->
// above is the code to get the url from your frame
// now we place that url into the input box:
// document.getElementById("frameid").value = myframe; // with frameURL defined earlier
</script>
</head>
<body>
<p>|
<a href="#" onclick="javascript:getSrc(document.getElementById('myframe'))">Get src</a> - displays with alert</p>
<iframe id="myframe" src="http://www.alianzaporlasolidaridad.org" style="width:80%; height:80%;"></iframe>
<br>
<br>
<input Id="frameid"><p>frameurl not showing in input</p>
<a href="#" onclick="javascript:setSrc(document.getElementById('myframe'), document.getElementById('frameid').value)">Get src</a> - displays with alert</p>
</body>
</html>
Vean que en la funcion "getSrc" he realizado todo tipo de pruebas guiándome por los métodos/propiedades que aparecen colgados del iframe cuando le das al F12 rn firefox.
Lo que necesito es capturar la url completa (lo mismo que se almacena en el historial de navegación)
¿Alguien me puede ayudar?
Un saludo
Valora esta pregunta


0