может кто-нибудь помочь, я пытаюсь добавить содержание html по ссылке в URL-адрес iframe, чтобы каждая ссылка изменила URL-адрес в iframe.
, поэтому вы получите результат при нажатии на первую ссылку было бы что-то вроде:
https://cars.com/cars.html?car_id=6230
////////////////////////// ////////////////////////////////////////////////
<div id="clickLink">
<a href="">6230</a>
<a href="">2322</a>
</div>
<script>
(function( w, d ){
function gElm( elm ){
return d.getElementById( elm ) ? d.getElementById( elm ) : false;
}
var iframe = d.createElement( 'iframe' ),
src = "https://cars.com/cars.html";
iframe.width = "100%";
iframe.height = "500px";
iframe.id = "c_iframe";
iframe.src = src;
d.body.appendChild( iframe );
gElm( 'clickLink' ).addEventListener( 'a', function( e ){
if( e.stopPropagation )e.stopPropagation();
if( e.cancelBubble ) e.cancelBubble();
if( e.preventDefault ) e.preventDefault();
console.log( e.target.innerHTML );
gElm( 'c_iframe' ).src = src + "?car_id=" + e.target.innerHTML;
}, false );
})( window, document );
</script>