Re: [crx] Popup.html no longer opening links using chrome.tabs.create. Script permissions error?

1,380 views
Skip to first unread message

PhistucK

unread,
Nov 11, 2012, 1:51:45 AM11/11/12
to Tom Swartz, chromium-...@chromium.org
Yes, use addEventListener instead and put the script in a separate .js file and reference it using <script src="something.js"></script>.

PhistucK



On Fri, Nov 9, 2012 at 8:48 PM, Tom Swartz <tom.sw...@gmail.com> wrote:
Hi All, 

I have an extension used for quick access to in-house network addresses. 

However, it has come to my attention that extensions no longer support in-line scripting, thus not allowing my popup.html file to create new tabs with the links. 
I've attached the manifest, but I'll paste the relevant bits of the popup.html here:




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script> -->
<title>Penn Manor Speed Dial Extension</title>
<link rel="stylesheet" href="styles2.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=ascii" />
</head>
<body>
<div id="container">
<div id="top">
<div id="header">
<div id="title">
<h1 class="font font-shadow"><span>Penn Manor</span> Speed Dial</h1>
</div>
</div>
</div>
<div id="columns">
<div id="main">
<div class="col box">
<h3 class="font">District Links</h3>
<ul>
<li class="arrows"><a href="http://www.aesoponline.com/" onclick="chrome.tabs.create({url:this.href})">Aesop</a></li>
<li><a href="http://blogs.pennmanor.net/list/" onclick="chrome.tabs.create({url:this.href})">Blogs@PM</a></li>
....... 
</ul>
</div>
    </div>
</div>
</div>
</body>
</html>

Does anyone know of a way that I could quickly and easily fix this?
I have about 30 links in the popup, if that helps. 

Thanks in advance!

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msg/chromium-extensions/-/EApTgX2dPOYJ.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.

Tom Swartz

unread,
Nov 11, 2012, 4:31:34 PM11/11/12
to chromium-...@chromium.org, Tom Swartz
Hi PhiStucK,

Thanks very much for the quick reply.

I've seen this suggestion elsewhere, but I'm not quite certain how to apply it.

I realize that I would need to create a .js file with the onclick="chrome.tabs.create({url:this.href}) code, but how would I reference it in the popup.html?

Also, isn't there a block on javascript outright? Isn't there an extra step to permit the javascript to run? Could you please provide information regarding this?

Thanks!
To unsubscribe from this group, send email to chromium-extensions+unsub...@chromium.org.

PhistucK

unread,
Nov 12, 2012, 2:11:40 AM11/12/12
to Tom Swartz, chromium-...@chromium.org
This is a basic web development question and unfortunately, this is not the right group for such discussion.

This tutorial shows examples that should answer your questions -

If you still cannot get it to work at all, you better search for some general web development forums/tutorials.

PhistucK




To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

Tom Swartz

unread,
Nov 12, 2012, 8:29:11 AM11/12/12
to chromium-...@chromium.org, Tom Swartz
Hi PhistucK,

Thanks again for the reply.

I do not intend to sound forward, but it seems that this is more of a Chrome extension question, rather than a basic web development question. I hope that my frustration does not come off as aggression. 

What is the 'approved' way of opening links from the Popup.hmtl page?

I'm aware that, since Manifest Version 2, inline javascript is no longer usable by the extensions. 
However, my point being that, despite the fact that I've used Google's tutorials to create the extension for Manifest v1, there is no clear way to transition to v2. 

I have seen many posts on StackExchange and elsewhere pointing to the fact that you could use the addEventListener, and still others saying that it is better to use the 'built in' chrome.tabs.create( { url: "http://www.URLHERE.com"} ); 
I don't wish to use 'buttons' within the popup.html window, but rather textual 'links' in the traditional sense; would I be correct in thinking that the addEventListener is likely out?

Furthermore, it's not quite clear where the Chrome API code is to be included. Google's Developer page (http://developer.chrome.com/extensions/tabs.html) simply explains the API syntax and then tells you to download and use a whole suite of examples. 


In it's most simple sense, I just wish to know how to display web-links in the popup.html and open them in a new tab once clicked. 

Do you have any advice on how to proceed? 



PhistucK




To unsubscribe from this group, send email to chromium-extensions+unsubscribe...@chromium.org.

PhistucK

unread,
Nov 12, 2012, 9:00:58 AM11/12/12
to Tom Swartz, chromium-...@chromium.org
Opening regular links (nothing that execute JavaScript) can be achieved by something like that -
<a href="http://www.google.com/" target="_blank">Some link</a>

If you want to call Chrome APIs, you have to put all of the JavaScript code in an external file and reference it using (for example) <script src="code.js"></script>.
If you want the links to do more than just open URLs, you must use theLinkElement.addEventListener("click", doSomething, false) or theLinkElement.onclick = doSomething and the like.


PhistucK




To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
Reply all
Reply to author
Forward
0 new messages