С помощью jQuery вы можете легко получить любой элемент из iframe, подключить обратный вызов события, например, при щелчке и действовать соответственно, например. просмотрите страницу anywher, которую вы требуете.
пример,
http://jsfiddle.net/Lmx9X/show/
увидеть код здесь,
http://jsfiddle.net/Lmx9X/
JS
$(document).ready(function(){
/*define a callback function to all anchors of iframe*/
$('#subpage').contents().find('a').on('click',function(e){
/*prevent the default behaviour of navigating to the href of the anchors*/
e.preventDefault();
/*do whatever you require, here for example a dialog is presented and navigates the parent page to the href url*/
if (confirm('Prevented iframe from navigating to page. Do you want outer page to navigate instead??')) {
var url = $(this).attr("href");
window.location.href = (url.indexOf("#")==0?window.location.href:"")+$(this).attr("href");
}else{
alert("ok, will not navigate!");
}
});
});
html
<iframe id="subpage" src="http://jsfiddle.net/s22Jm/1/show"></iframe>
приемлемо использовать jQuery? – melc
@melc. Я открыт для использования jquery..у вас, пожалуйста, поделитесь мной кодом .. (я не эксперт в jquery) ... спасибо заранее! –
'top.location.href = ...' должен делать то, что вам нужно. – Teemu