简体   繁体   中英

Stop Iframe page from redirecting

http://kenzshop.com/lightbox/

User types url in input field, and clicks "Go To" button. Page should just view in iframe. But when typing in a url like espn.com the clicking button, page will momentarily display, then the whole page (kenzshop.com/lightbox) will redirect to espn.com.

Also, when I try yahoo.com in the iframe, nothing at all happens. Is something mis-coded here? Or just something within those sites not allowing them to be viewed in iframes?

Also, not sure if it is ok to ask this in same thread, but is there a way of the user clicking the Enter Button on the keyboard creating the same effect as having to click the "Go To" button?

<script type="text/javascript">
<!--//
function urlink(iframe,src){
document.getElementById(iframe).src = src;
}
//-->
</script>

< / head>

<div style="background-image: url('https://s3.amazonaws.com/cloud-host.mobi/preview- iphone4g.png'); width: 327px; height: 730px; padding: 135px 28px 0px 33px; background-repeat: no-repeat;">

<form>
<div style="position:relative; top:9px; left:2px;"><input style="float:left;"type="text" size="40" value="http://" name="url">
<input type="button" onclick="urlink('I1',this.form.url.value)" value="Go To"></div>
</form>

<iframe id="I1" src="" style="height: 489px; width: 327px;" frameborder="0" marginwidth="0" scrolling="yes" width="320" height="240"></iframe> 

</div>

Thanks!! Ken

espn.com probably has some JavaScript to break itself out of an iframe. I'm afraid there's not much you can do there. Most sites do not have this, though.

For the enter button, use a <form> tag with the action parameter. Wrap it around your <input> box. See http://www.w3schools.com/tags/tag_form.asp for examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM