2

我尝试使用此代码,但没有奏效。

<a href="http://altodesign.pt/#portfolio" onClick="loadintoIframe('myframe,'portfolio/mmteam.html');">

4

3 回答 3

0

永远不会使用javascript ...

我查看了您的网页(有很多要学习的内容,例如在页面末尾添加脚本,创建一个全局 javascript 对象来保存所有网站操作等......但这不是问题)

我可以看到,即使你跳到#CONTACTOS你根本没有使用哈希......你应该!

使用哈希可以让您执行以下操作:

http://altodesign.pt/#portfolio-cooptaxis

这将跳转到portfolio锚点并将其加载cooptaxis.html到 iframe 中并且您javascript:loadintoIframe('myframe', 'portfolio/mmteam.html')完全停止使用,因为这将导致谷歌分析和爬虫不跟进您的链接,例如...

您的方法可能很简单,例如

$(function() {

    // let's see if we have an hash on the page
    var hash = document.location.hash;

    if(hash.length > 0) {
        if(hash.instr('-') >= 0) {
           // supposing will have only one char '-'
           var img = hash.split('-')[1]; 

           // let's remove the frame info from the hash
           hash = hash.split('-')[0]; 

           // there's a call to load into the iframe, let's load it
           $("#myframe").attr("src", "portfolio/" + img + ".html")
        }

        // let's fly
        jumpTo(hash);
    }

    // let's disable the anchor links by default and use the hash
    $("a[href^=#]").click(function() {
        // for all links that start with the hash, let's...
        document.location.hash = $(this).attr("href");
        return false;
    });

    $(window).bind('hashchange', function() {
        // everytime the hash changes let's fly
        jumpTo(document.location.hash);
    });
});

function jumpTo(anchor) {
    var a = $("a[name='" + anchor.replace('#','') + "']"),
        pos = 0;
    if(a.length > 0) {
        // we have found the anchor, let's grab it's top position
        pos = a.position().top;
    }

    // if we got here and pos === 0, we did not found the anchor
    // for the given hash... maybe the user is playing around ...

    // and we shall fly
    $('body,html').animate({
        scrollTop: pos
    }, 800);
}

justthis 将允许您避免使用 javascript 来跳转链接,因为它们现在所拥有的一切都很简单:<a href="#PORTFOLIO">Portfolio</a>

于 2012-11-09T22:16:44.717 回答
0

假设您有 page1.html,其中有一个指向 page2.html 的链接,您希望它在 page1.html 的 iframe 中打开

in page1.html
<a href="page2.html" target="iframe-name">link</a>
<iframe name="iframe-name"></iframe>

然后你可以添加任何你想要的锚。只需命名您的 iframe,然后在链接中定位它!

于 2012-11-09T22:30:31.943 回答
0

你可以试试这样的

a href="javavcipt:document.getElementById('myframe').src = 'portfolio/mmteam.html';"

于 2012-11-09T21:55:33.347 回答