使用iframe和PHP

时间:2015-05-25 19:39:12

标签: php iframe

我在iframe中有几个关于php内容的问题。

  1. 我想创建一些导航链接并定位iframe。有简单的方法吗?

  2. 你认为我只能用Ajax或Ahah做到这一点吗?

  3. 这是我到目前为止所尝试的,但它不起作用。

  4. 这是我的代码。

          // HERE ARE NAVIGATION LINKS
    
            <header>
            <h1>Välkommen till Min Sida</h1><br>
                <nav>
                    <a href="index.php?go=welcome">HOME</a>
                    <a href="index.php?go=about">ABOUT ME</a>
                    <a href="index.php?go=contact">CONTACT</a>
                    <a href="index.php?go=subscribtion">SUBSCRIBE</a>
                </nav>
            </header>
    
    
        // HERE IS MY IFRAME WHERE I WANT TO OPEN MY PHP FILES  
    
    
    
    <div class='content' >
      <iframe>
    
        <?php
    
    $go = @$_GET["go"];
    
                switch($go){
    
    
        // IF I CLICK ON "WELCOME" FROM THE NAVIGATION BAR, OPEN THIS LINK IN My IFRAME
    
                    case "welcome";
                    include("welcome.php");
                    break;
    
    
        // IF I CLICK ON "ABOUT" FROM THE NAVIGATION BAR, THIS LINK IN MY IFRAME
    
    
    
    
    
     case "about";
            include("newarrivals.php");
            break;
    
    
     // AS "DEFAULT", SHOW THIS IN THE IFRAME
    
        default;
        echo 
    
                <figure>
                <img src="figure.png"  alt="Figure 1" style="max-width:80%; height:auto;">
                <figcaption> <h6> Illustration: Mehmet Akb. </h6> </figcaption>
                </figure>
    
    break;
    }
    ?>
    
    </iframe> 
    </div>
    </div>
    </body>
    

2 个答案:

答案 0 :(得分:0)

您可以使用javascript重新加载iframe

  1. 将您的iframe内容移至<iframe id="contentFrame"></iframe>
  2. 在iframe <a href="javascript:void(0)" onclick="goto('icontent.php?go=welcome')">HOME</a> <a href="javascript:void(0)" onclick="goto('icontent.php?go=about')">ABOUT ME</a> <a href="javascript:void(0)" onclick="goto('icontent.php?go=contact')">CONTACT</a> <a href="javascript:void(0)" onclick="goto('icontent.php?go=subscribtion')">SUBSCRIBE</a>
  3. 中添加一些ID
  4. 更改您的链接操作

    function goto(url) {
        document.getElementById("contentFrame").contentWindow.location.replace(url);
    }
    
  5. 创建此javascript函数

    override func viewDidAppear(animated: Bool) {
        self.giphyBackground(Title: "dancing") { [weak self] (gifUrl) -> Void in
            let gifView = FLAnimatedImageView(frame: self!.giphy.frame)
            gifView.animatedImage = FLAnimatedImage(animatedGIFData: NSData(contentsOfURL: NSURL(string: gifUrl)!)!)
            self?.view.insertSubview(gifView, aboveSubview: self!.giphy)
        }
    }
    

答案 1 :(得分:0)

如果您的Iframe有名称,您可以使用 目标 属性来确定iframe名称,例如

<iframe name="topframe"></iframe>
<a href="xxx" target="topframe">