2010-11-01 51 views
0

我想将铬扩展标签信息(标题,URL)传递到我的服务器上的PHP页面。我有它显示的信息,但当我尝试写信息的iframe,我无法获得信息到.php页面。想要将带有标签和URL信息的URL传递给PHP页面

有没有更好的方法来做到这一点?谢谢!

{ 
    "name": "XXXXXX", 
    "version": "1.0", 
    "description": "Test.", 
    "browser_action": { 
    "default_icon": "icon.png", 
    "popup": "popup.html" 
    }, 
    "permissions": [ 
    "tabs", 
    "http://www.xxxxxxxx.com/*", 
    "bookmarks" 
    ] 
} 


<html> 
<head> 
<style type="text/css"> 
body {width:100; height:50;} 
</style> 
<script language="Javascript"> 
chrome.tabs.getSelected(null,function(tab) { 
    var tablink = tab.url; 
    var tabtitle = tab.title; 
    alert(tablink); 
    alert(tabtitle); 

    document.write('<iframe src=http://www.xxxxxxxx.com/index.php?link=' + tablink + '&title=' + tabtitle + 'width=100 height=50 frameborder=0 scrolling=no'); 
}); 
</script> 

</head> 

<body> 

</body> 
</html> 

回答

0

我想出了一个解决方案。

<html> 
<head> 
<style type="text/css"> 
    body {width:100; height:50;} 
</style> 
<script language="Javascript"> 
    chrome.tabs.getSelected(null,function(tab) { 
     var tablink = tab.url; 
     var tabtitle = tab.title; 

     if (tablink != "") 
     { 
      var url = "http://www.xxxxxxxx.com/index.php"; 
      document.getElementById("phpcontent").innerHTML = ""; 
      document.getElementById("phpcontent").innerHTML += "<iframe src='" + url + "?link=" + tablink + "&title=" + tabtitle + "' width='100' height='50' frameborder='0' scrolling='no'></iframe>"; 
     } 
     else 
     { 
      exit(); 
     } 
    }); 
</script> 

</head> 

<body> 
    <span id="phpcontent"></span> 
</body> 
</html>