2013-01-25 15 views
0

我想用PHP設置一個iframe的網址,我的網址是這種格式:http://mysite.com/s/其中=數字,我想打一個按鈕,增加在1 URL的數量和重新加載iframe。重新定義通過PHP代碼的iframe網址

<html> 
    <head> 
     <meta charset="utf-8" /> 
     <link href="style.css" rel="stylesheet" type="text/css" /> 
    </head> 

    <body> 
     <form class="topBorder"> 
      <p> 
       <?php 
        $site = 6394100; 

        function NextSite($sites) 
        { 
         $sites += 1; 
         return 'http://mywebsite.com/s/' . $sites . '/'; 
        } 

       ?> 
       <a href="<?php echo NextSite($sites); ?>" target="frame"> Next </a> 
      </p> 
      <iframe name="frame" id="frame" src="http://mywebsite.com/s/" class="gagFrame"></iframe> 
     </form> 
    </body> 
</html> 

回答

1

那麼你可以幫助一個簡單的JS函數。請參閱下面的修改代碼。我沒有測試過,但你應該明白這一點。

編輯:

你需要把它做了ajax方式。把你的PHP函數在一個文件中說loadurl.php:

  <?php 
       $site = 6394100; 

        $sites += 1; 
        echo 'http://mywebsite.com/s/' . $sites . '/'; 
      ?> 

現在在你的HTML代碼,請執行以下操作:

<html> 
<head> 
    <meta charset="utf-8" /> 
    <link href="style.css" rel="stylesheet" type="text/css" /> 
</head> 

<body> 
    <form class="topBorder"> 
    <script type="text/javascript"> 
    function loadURL() 
    { 
     $.get('pathToloadurl.php',success(data) 
     { 
      window.frames[siteFrame].location =data; 
     }); 
    } 
    </script> 
    <button type="button" onClick="loadURL()">Next</button> 
    <iframe name="siteFrame" id="frame" src="http://mywebsite.com/s/" class="gagFrame"></iframe> 
</form> 
+0

其實,沒有發生 – GmodCake

+0

看到我的編輯使用Ajax來獲取URL。您需要包含JQUERY才能正常工作。 – beNerd

+0

如何包含jquery?我不知道它是什麼 – GmodCake