This code works:
(function() {
var scr = document.createElement('script');
var head = document.getElementsByTagName('head')[0];
window.insert = function(data) {
alert(data);
};
scr.src = 'http://nocore.info/test.php?callback=insert';
scr.type = 'text/javascript';
head.appendChild(scr);
})();
It's tested using jsFiddle. What it does is it gets a string via JSONp and alerts it.
And so does this code:
(function(){var a=document.createElement("script"),b=document.getElementsByTagName("head")[0];window.insert=function(a){alert(a)};a.src="http://nocore.info/test.php?callback=insert";a.type="text/javascript";b.appendChild(a)})();
But when I type javascript: in the URL bar followed by this code, I get nothing. Why exactly is this? I'm not aware of any such behavior. I can set window.* variables in the URL bar and I can manipulate DOM.
So what's the problem here guys?
Thanks guys. Appreciate your help.
<head/>