Reputation: 45
Firstly , i want to admit that i am not any good in javascript. In fact , it frustrates me to no end and i cannot seem to wrap my head around it , still giving it a shot.So i have this "js" file:
var url, tab,myNewTab;
function init(){
chrome.tabs.query({currentWindow: true, active: true},function(tabs){
url = tabs[0].url;
tab = tabs[0]
tabId = tabs[0].id;
processTab();
});
}
function processTab(){
chrome.tabs.update(tabId, {selected: true});
if (url.substring(0,5) === "http:")
{
console.log(window.location);
url = insert(url , 4 , "s");
}
myNewTab = window.open('https://alexanderproxy33.appspot.com','_newtab' );
myNewTab.onload = cont() ;
}
function insert(str, index, value) {
return str.substr(0, index) + value + str.substr(index);
};
function cont()
{
console.log(myNewTab.document.getElementById("input").value)
}
init();
There are many things that could have been done much better i guess but my question is this: the console.log line gives me an error cause null.I made the cont() function so it would load its elements so i could get them (as suggested by many people who are obviously right) but still nothing. The next part is a part of the html of the aforementioned site which i thought would trigger this:
<body>
<div class="box">
<h6>Basic Proxy</h1>
<center>
<form action="" method="get" accept-charset="utf-8" target="_blank">
<input name="url" type="text" class="txt" id="input" placeholder="type url here.." onfocus="this.value='';" />
<input type="submit" class="btn" value="Go" />
</form>
</center>
<p class="footer">Instructions: Just type the URL of any web page in the input box above (
<em>e.g. google.com</em> ) and hit Enter.</p>
<p class="footer"></p>
</div>
</body>
Thanks in advance
Upvotes: 1
Views: 118
Reputation: 2188
myNewTab.onload = cont() ;
is incorrect as you are executing cont
and then setting its return value (i.e. undefined
) as myNewTab.onload
. Therefore, that line should be myNewTab.onload = cont;
.
Upvotes: 2