Jump to content
Sign in to follow this  
Isabel Macedo

Conteúdo de URL

Recommended Posts

Isabel Macedo

Boas,

Estou a tentar obter o conteúdo de um URL com o seguinte código em jquery:

//Get current URL to share in facebook
chrome.tabs.getSelected(null, function(tab) {
document.getElementById('share2').innerHTML = tab.url;
console.log(tab.url);
  document.getElementById('share2').innerHTML=tab.data;
  console.log(tab.data);
});

Alguém sabe o que estou a fazer errado?

Share this post


Link to post
Share on other sites
Isabel Macedo

Sim eu sei...

Já tinha adicionado as permissões, mas mesmo assim não estou a conseguir.

manifest.json:

{
 "manifest_version": 2,
 "name": "teste-gmail",
 "description": "This extension will share the contents of your gmail.",
 "version": "1.0",


 "page_action": {
"default_icon": "icon.png",
"default_title":"Gmail",
"default_popup": "popup.html"
 },

"permissions": [
"http://www.gmail.com/ ",
"http://www.facebook.com/",
"https://www.gmail.com/",
"https://www.facebook.com/",
"tabs",
"storage"
 ],

 "background": {
"scripts": ["background.js"],
"persistent": false
 },

 "content_security_policy": "script-src 'self'; object-src 'self'"
}

popup.html:

<!doctype html>
<html>
<head>
	<!--<link rel="stylesheet" href="http://s3-ak.buzzfed.com/static/css/webfonts.css?v=1370354313" type="text/css" />-->
	<script src="fbbutton.js"></script>
	<script src="settings.js"></script>
	<!--<script src="sdk.js"></script>-->
	<style>
	  div span, iframe {
		height:50px!important;
		width:100px!important;
	  }
	</style>
</head>
<body>
	<div style="width:160px; height:200px; font: normal 21px/23px 'ProximaNovaSemibold',Helvetica,Arial,sans-serif">
	<div id="fb-root"></div>
		<form id="share" action="" method="">
			<label>
				<input type="checkbox" id="share2" name="share" /> <span style="position:relative; top:3px;margin-bottom:20px;c">Quer partilhar no face?</span>
			</label>
		   <div id= "share1"class="fb-share-button" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button" style="width:100px; height:50px;"></div>
		</form>		  
	</div>
</body>
</html>

fbbutton:

      //code from facebook
  window.fbAsyncInit = function() {
	FB.init({
	  appId	  : '326350284188834',
	  xfbml	  : true,
	  cookie	 : true, // enable cookies to allow the server to access the session
	  status	 : true, // check login status
	  version	: 'v2.0'
	});
  };

(function(d, s, id) {
 var js, fjs = d.getElementsByTagName(s)[0];

 if (d.getElementById(id))
  return
  js = d.createElement(s);
  js.id = id;
  js.src = "sdk.js";
  js.async = true;
  fjs.parentNode.insertBefore(js, fjs);
}

(document, 'script', 'facebook-jssdk'));


//Get current URL to share in facebook
chrome.tabs.getSelected(null, function(tab) {
document.getElementById('share2').innerHTML = tab.url;
console.log(tab.url);
  document.getElementById('share2').innerHTML=tab.data;
  console.log(tab.data);
});



//Share the URL im facebook
chrome.tabs.getSelected(null, function(tab) {
document.querySelector("div.fb-share-button").setAttribute("data-href", tab.url);
});

Edited by Rui Carlos
GeSHi

Share this post


Link to post
Share on other sites
HappyHippyHippo

leste o link ?

https://developer.chrome.com/extensions/whats_new#16

The methods getAllInWindow() and getSelected() have been deprecated. To get details about all tabs in the specified window, use tabs.query with the argument {'windowId': windowId}. To get the tab that is selected in the specified window, use chrome.tabs.query() with the argument {'active': true}.


IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites
Isabel Macedo

Tentei fazer o pedido de permissão ao utilizador, mas algo não está bem.

chrome.tabs.getSelected(null, function(tab) {
 document.getElementById('share2').innerHTML = tab.url;
 chrome.permissions.onAdded.addListener({permissions: ['tabs'], origins: ['google.com/']}) {
   console.log("The permissions are nedd.");
   document.getElementById('share2').innerHTML = tab.data;
   document.querySelector("div.fb-share-button").setAttribute("data-href", tab.url);
 });
});

Edited by Rui Carlos
GeSHi

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.