简体   繁体   中英

How do I put a third party website or link to a website to open in a frame on my webpage?

I am building a website and I want to open a third party website page in a frame on my webpage, what do I use? javascript? If so how do I write it? I am very new and don't know what I am doing.

如果您使用的是动态网址,则可以使用javascript,否则您将只需要iframe即可

<iframe src="http://www.stackoverflow.com" />

If you want them to click a link and then show the website in the iframe, it would be like so:

<a href="http://site.com/" target="iframe">site.com</a>
<iframe name="iframe"></iframe>

If you want to make it so that when a user click on a link, that link open in a certain frame, you should give that frame/iframe an ID. Then you can provide that ID as the target attribute of the anchor.

Lets say your frame looks like this

<frame src="somepage.html" id="myFrame">

Now you can open a page in that frame like this:

<a href="http://www.google.com" target="myFrame">Some link</a>

No need to use anything but plain HTML to accomplish that.

I'd use http://fancybox.net/
It's a light jQuery script that generates a good looking iFrame overlay. You can also use it for pictures and any other overlay.

Include jQuery and Fancybox and FancyBox CSS:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="jquery.fancybox-1.3.4.pack.js"></script>
<link rel="stylesheet" href="/fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />

Then add the link:

<a id="iframe" href="http://www.example.com/">This goes to iframe</a>

And initialize FancyBox using jQuery:

$(document).ready(function() {
    /* This is basic - uses default settings */
    $("a#iframe").fancybox();
});

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