javascript - How to prevent an iframe to display external websites? -


let's display iframe on iframe.domain.com. want iframe able display content iframe.domain.com or sub.domain.com. websites contain link external websites, example google.com. if users clicks on link redirecting him google.com, want iframe redirected sub.domain.com

how can that?

you can use e.preventdefault() achieve achieve this

now onclick handler set on links in frame can use function

function onloadif(frame) {     var elements = frame.getelementsbytagname('a'),         len = elements.length;      while( len-- ) {         $(elements[len]).on('click', function(e){           e.preventdefault();         }     } } 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -