I want to add any URL of CurrentTabs here in this "popup.js" to bookmarks.
function GetUrls()
{
var CurrentTabs = new Array();
chrome.tabs.query({}, function (tabs) {
for (var i = 0; i < tabs.length; i++)
{
CurrentTabs[i] = tabs[i];
}
for (var i = 0; i < CurrentTabs.length; i++)
{
document.write("<b>" + CurrentTabs[i].title+"</b>"+"<br/><a href='" + CurrentTabs[i].url + "' target='_blank'>" + CurrentTabs[i].url + "</a><br/><br/>");
}
});
}
window.addEventListener("DOMContentLoaded", GetUrls());
document.getElementById("addBookmark").addEventListener('click',addGoogleBookmark);
function addGoogleBookmark()
{
chrome.bookmarks.create({title:"Extension bookmarks",parentId:?????,url:"http://www.google.com"});
alert("Added to bookmarks");
}
The problem here in the function addGoogleBookmark() what is the parentId?
Any idea?
And this is popup.html:
<!DOCTYPE html>
<html>
<head>
<title>Links Collector</title>
<script src="popup.js"></script>
</head>
<body>
<input id="addBookmark" type="button" value="Add a Google bookmark"></input>
<style>
body {
width:500px;
height: 300px;
}
</style>
</body>
</html>
As described in the official documentation:
parentId ( optional string )
The id of the parent folder. Omitted for the root node.
As the parameter is optional for the chrome.bookmarks.create function, you can omit it for a default usage. In this case, the bookmark will go in the Other Bookmarks folder.
For more advanced usage, take a look at the chrome.bookmarks Documentation
Related
i am trying to make html page, that should shows all the nodes in xml file. there are other ways but i want to do it using javascript DOM through recursive function. i've tried this. suggest please.
**
<!DOCTYPE html>
<html>
<head>
<title>Adi the great</title>
<script type="text/javascript">
var httpreq=null;
var response=null;
setTimeout("loadDoc()",100);
setTimeout("loadDocument()",1000);
function loadDoc()
{
if(window.XMLHttpRequest)
httpreq=new window.XMLHttpRequest();
else
httpreq=new ActiveXObect("Microsoft.XMLHTTP");
httpreq.open("get","ADI_SUPPORT.xml",true);
httpreq.send(null);
//httpreq.onreadystatechange=loadDocument;
}
function loadDocument()
{
res=httpreq.responseXML;
play("loaded");
traverse(res.documentElement);
}
function traverse(element)
{
play("inside function with element =>"+element.nodeName);
len = element.childNodes.length;
play(element.nodeName + " is node with len = "+len);
if(len>1)
{
play("len is > 1");
temp="";
for(i=1;i<len;i+=2)
temp+=element.childNodes[i].nodeName+",";
play("temp="+temp);
for(i=1;i<len;i+=2)
{
play("started element "+element.childNodes[i].nodeName+" at i="+i);
traverse(element.childNodes[i]);
play("ended element "+element.childNodes[i].nodeName+" at i="+i);
}
}
else
{
play("node ends with "+element.textContent);
}
}
function play(x) { document.write(x + "<br/>"); }
</script>
</head>
<body>
</body>
</html>
**
I have an HTML page:=
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src = "http://localhost/Stats/Stats.js">
</script>
</head>
<body>
<button onclick="test()">Test</button>
</body>
</html>
But when I use Firebug on this page, their seems to be many unwanted and unknown script tags and iframes.
I posted a picture but my rep won't let me.
What can I do?i tried running it through disk (using file:/// protocol) and in xampp (using http://localhost/) but no difference.
Just give the scripts and iframes that you do want a class.
Then, after the page has loaded, look at the document to get a list of all of the (a) script elements and (b) iframe elements. Simply iterate through these lists and remove any that don't contain the class you've assigned to permitted or desired elements.
Here's a short snippet that adds an event listener to the 'load' event of the window. When fired, this function nukes any iframe and script whose class doesn't contain 'desired'.
The code contains 2 scripts and 2 iframes. After the onDocLoaded function has run, there are only one of each remaining.
<!DOCTYPE html>
<html>
<head>
<script class='desired'>
"use strict";
function forEachNode(nodeList, func)
{
var i, n = nodeList.length;
for (i=0; i<n; i++)
{
func(nodeList[i], i, nodeList);
}
}
window.addEventListener('load', onDocLoaded, false);
function onDocLoaded()
{
var scriptElems = document.getElementsByTagName('script');
alert("initially, there are " + scriptElems.length + " scripts");
forEachNode(scriptElems, checkForSpecificClass);
scriptElems = document.getElementsByTagName('script');
alert("there are now " + scriptElems.length + " scripts");
///////////
var iframeElems = document.getElementsByTagName('iframe');
alert("initially, there are " + iframeElems.length + " iframes");
forEachNode(iframeElems, checkForSpecificClass);
iframeElems = document.getElementsByTagName('iframe');
alert("there are now " + iframeElems.length + " iframes");
function checkForSpecificClass(elem, index, list)
{
if (elem.classList.contains('desired') != true)
elem.parentNode.removeChild(elem);
}
}
</script>
<script src='someInjectedCrap.js'></script>
</head>
<body>
<iframe class='desired'>
</iframe>
<iframe src='someInjectedCrap.html'></iframe>
</body>
</html>
I am attempting to use Google Feed API to display three current event listings for our homepage. This is to circumvent some of the issues we are having with a third part calendar application.
However, with the feed limit set to 3, the only listings that will show up for me are from Jan. 18. Is there a way to make the code show only current or future events?
Thanks in advance for any help.
HTML
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="http://www.google.com/jsapi">
</script>
</head>
<body>
<div id="feed"></div>
</body>
</html>
JavaScript
google.load("feeds", "1");
var feedcontainer=document.getElementById("feed");
var feedurl="http://25livepub.collegenet.com/calendars/publishers-calendar-7.rss";
var feedlimit = 3;
var rssoutput = '';
function rssfeedsetup(){
var feedpointer=new google.feeds.Feed(feedurl);
feedpointer.setNumEntries(feedlimit) ;
feedpointer.load(displayfeed);
}
function displayfeed(result){
if (!result.error){
var thefeeds=result.feed.entries;
for (var i=0; i<thefeeds.length; i++){
var untrimContent = thefeeds[i].content;
var trimContent = untrimContent.split("<br>", 2);
rssoutput+="<div><a href='" + thefeeds[i].link + "'>" + thefeeds[i].title + "</a></div>" + trimContent;
feedcontainer.innerHTML=rssoutput;
}
} else {
feedcontainer.innerHTML = "Error Loading Events";
}
}
window.onload=function(){
rssfeedsetup();
};
In my JavaScript code I have the following line:
document.write("</form><button style='margin-top:100px; width:150px; position:absolute; left:50%; margin-left:-75px' type='button' onclick='Proceed('test')'>Se resultat</button>");
The style and type properties work fine but when I try to pass a parameter to the JavaScript function Proceed it doesn't work. I have also tried (\'test\')
How do I solve this problem?
Edit: full html script
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Title here.</title>
<script>
function Proceed(var test)
{
alert(test);
}
</script>
</head>
<body style="font-family:Palatino">
<img src="logo.png"/>
<hr/>
<h1 style="text-align:center">Description here.</h1>
<script>
if (window.XMLHttpRequest)
{
request=new XMLHttpRequest();
}
else
{
request=new ActiveXObject("Microsoft.XMLHTTP");
}
request.open("GET","data.xml",false);
var XMLdocument;
request.onreadystatechange=function()
{
if (request.readyState==4)
{
XMLdocument = request.responseXML;
}
};
request.send();
var questions = XMLdocument.getElementsByTagName("question");
for(i = 0; i < questions.length; i++)
{
var x = questions[i];
var questionvalue = x.getElementsByTagName("questionvalue");
document.write("<p style='margin-top:50px; font-size:20px; font-weight:bold; text-align:center'>" + questionvalue[0].childNodes[0].nodeValue + "</p>");
var answers = XMLdocument.getElementsByTagName("answer");
document.write("<form>");
for(n = 0; n < answers.length; n++)
{
y = answers[n];
var answervalue = y.getElementsByTagName("answervalue");
document.write("<input style='margin-left:43%; margin-right:20px;' type='radio' name='" + questionvalue[0].childNodes[0].nodeValue + "' value='" + answervalue[0].childNodes[0].nodeValue + "'>" + answervalue[0].childNodes[0].nodeValue + "<br/>");
}
document.write("</form><button style='margin-top:100px; width:150px; position:absolute; left:50%; margin-left:-75px' type='button' onclick='Proceed(\"test\")'>Se resultat</button>");
}
</script>
</body>
</html>
It doesn't work because it's invalid HTML:
document.write("</form><button ... onclick='Proceed('test')'>...</button>");
Will be written as:
</form><button ... onclick='Proceed('test')'>...</button>
When it's written to the DOM, the quoting style of onclick dictates where it ends, essentially making the value of onclick Proceed(. You need to change your quoting characters:
document.write("</form><button ... onclick=\"Proceed('test')\">...</button>");
or:
document.write("</form><button ... onclick='Proceed(\"test\")'>...</button>");
Edit: See this plunkr for a simple example
Changing them to escaped double quotes should work for you.
document.write("</form><button style='margin-top:100px; width:150px; position:absolute; left:50%; margin-left:-75px' type='button' onclick='Proceed(\"test\")'>Se resultat</button>");
You could change the single quotes to escaped double quotes:
onclick='Proceed(\"test\")'
I have function that opens up a window, and the values from the newly opened window are listed in the opener window.
The 2nd window - has this function:
function AddOtherRefDoc(name, number) {
var remove = "<a href='javascript:void(0);' onclick='removeRefDoctor(this)'>Remove</a>";
var html = "<li><b> Referral Doctor: </b>"+name+"<b>, Referral No: </b>"+number+ " " +remove+" <input type='text' name='ref_docs' value='"+name+"'></input><input type='text' name='ref_nos' value='"+number+"'></input></li>";
opener.jQuery("#r_docs").append(jQuery(html));
}
The function that calls the one above is:
function addRefDoc(){
var count = 0;
var ref_docarray ;
var ref_noarray ;
<%for(int i1=0; i1<vec.size(); i1++) {
prop = (Properties) vec.get(i1);
String ref_no = prop.getProperty("referral_no","");
String ref_name = (prop.getProperty("last_name", "")+ ","+ prop.getProperty("first_name", ""));
%>
if(document.getElementById("refcheckbox_<%=ref_no%>").checked) {
count++;
if ((ref_doctor!=null)&&(ref_doctor!="")&&(ref_docno!=null)&&(ref_docno!="")) {
ref_docarray = ref_doctor.split(";");
ref_noarray = ref_docno.split(";");
if ((containsElem(ref_docarray,"<%=ref_name%>"))||(containsElem(ref_noarray,<%=ref_no%>))) {
alert("Referral doctor " + "<%=ref_name%>" + " already exists");
} else {
AddOtherRefDoc("<%=ref_name%>", <%=ref_no%>);
}
} else {
AddOtherRefDoc("<%=ref_name%>", <%=ref_no%>);
}
}
<%} %>
self.close();
}
function containsElem(array1,elem) {
for (var i=0;i<array1.length;i++) {
if(array1[i]==elem){
return true;
} else{
return false;
}
}
}
When this function is called, it is supposed to carry the 2 input elements "ref_docs" and "ref_nos" into the page that opened this window. But it is not doing so. It lists the elements alright but when I try to use "ref_docs" and "ref_nos" in another Javascript function in the 1st window, I see that "ref_nos" and "ref_docs" are empty.
What am I doing wrong?
function updateRd(){
var ref_docs = jQuery("#updatedelete").find('input[name="ref_docs"]');
var ref_nos = jQuery("#updatedelete").find('input[name="ref_nos"]'); alert(ref_docs.val() + ref_nos.val());
var rdocs = new Array();
var rnos = new Array();
ref_docs.each(function() { rdocs.push($(this).val()); } );
ref_nos.each(function() { rnos.push($(this).val()); } );
$('#r_doctor').val(rdocs.join(";"));
$('#r_doctor_ohip').val(rnos.join(";")); }
–
This function returns an error saying "ref_docs" and "ref_nos" are undefined.
I think it is trying to use the jQuery on the other page to find "#r_docs" on the current page.
Try:
jQuery(opener.document).find("#r_docs").append(html);
UPDATE:
I created index.html:
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> - jsFiddle demo</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.js"></script>
<script type="text/javascript">
window.jQuery = jQuery;
function openChild ()
{
var mychildwin = window.open("child.html");
}
</script>
</head>
<body>
<input type="button" value="click" onclick="openChild();" />
<div id="r_docs">
Redocs here.
</div>
</body>
</html>
and child.html:
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> - jsFiddle demo</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.js"></script>
<script type="text/javascript">
function AddOtherRefDoc(name, number) {
var remove = "<a href='javascript:void(0);' onclick='removeRefDoctor(this)'>Remove</a>";
var html = "<li><b> Referral Doctor: </b>"+name+"<b>, Referral No: </b>"+number+ " " +remove+" <input type='text' name='ref_docs' value='"+name+"'></input><input type='text' name='ref_nos' value='"+number+"'></input></li>";
jQuery(opener.document).find("#r_docs").append(html);
}
</script>
</head>
<body>
<input type="button" value="click" onclick="AddOtherRefDoc('name', 42);"/>
</body>
</html>
UPDATE2:
in your update function document.updatedelete has no attributes ref_docs and ref_nos.
try:
jQuery("#updatedelete")
.find('input[name="ref_docs"], input[name="ref_nos"]')
Where your form is
<form id="updatedelete" ... >
Your function that accesses the DOM elements is incorrect. updatedelete is not a property of document, nor will accessing a ref_docs or ref_nos property automatically build a collection of input elements. Since you're using jQuery already, try this:
var ref_docs = $('input[name="ref_docs"]');
var ref_nos = $('input[name="ref_nos"]');
That will give you Array (or at least array-like) objects that will let you access your inputs:
var rdocs = new Array();
var rnos = new Array();
ref_docs.each(function() { rdocs.push($(this).val()); } );
ref_nos.each(function() { rnos.push($(this).val()); } );
$('#r_doctor').val(rdocs.join(";"));
$('#r_doctor_ohip').val(rnos.join(";"));