开发者

Opening a link in the same page

I have put a link in an HTML document. How can I open the linked document (link1.html) under the link within the same page?

links.html:

<body>
   开发者_如何学JAVA <h3>Links</h3>
    <a href="link1.html">link1</a> 
</body>

output like:

Links [link1]


content of link1.html


<a href='link1.html' target='myIframe'>link1</a><br />
<iframe name='myIframe'></iframe>

If you want it to be less crappy, I suggest you use JavaScript.


Try to use the property tag "Target" which is used to specify, where the document to be opened, means new window or same page or new tab.. eg: Click Here

There are six values of the target tag like parent,blank and so on..


As has been sayed in the comments:
Probably what you want is an <iframe>. It can be used to embed a web page into an HTML document. You can see more info here. Below is an example.

In your case:

<body>
    <h1>Links</h1>
    <a href="link1.html">link1</a>

    <h2>Contents of link1</h2>
    <iframe src="link1.html" width="500" height="400"></iframe>
</body>

Update: To show the IFrame when the link's clicked, you can use this code instead:

<body>
    <h1>Links</h1>
    <a href="#" onclick="document.getElementById('contents1').style.cssText = ''">link1</a>

    <div id="contents1" style="display:none;">
        <h2>Contents of link1</h2>
        <iframe src="link1.html" width="500" height="400"></iframe>
    </div>
</body>


I am afraid you'll have to do this using some kind of javascript Ajax call to load the other page under the link. Another technique could be to include in your link1.html the same header as in links.html, but you're going into copy/paste spaghettiness...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜