JSONP with document.write - jsonp

I'am loading a script jspnp-like
var s = document.createElement("script");
s.src = "http://scripturl";
s.type = "text/javascript";
document.getElementById("ad").appendChild(s);
when the script contains an alert it just works. But the real script needs to "document.write". But the document.write is never output. Any ideas why? The script console does not show any errors.

This question is is similar to the questions found
http://www.webmasterworld.com/javascript/4401935.htm
and
document.write in jsonp callback
It seems that calling document.write() is calling document.open(), which erases everything you previously have written. By the time the document.write() is executed, the page has already finished loading.
Take a look at the solutions provided in the links above and try modifying them for your specific needs. Try using an iframe and write to that.

Related

[JETPACK COMPOSE]: is there a way to restart whole app programmatically?

I need a way to make my app close and opens again. Or just restart everything inside of it.
Since the issue with my app can be fixed by closing app and opening again (When creating user the loading function to firebase the collection inside user document does not load for some reason)
Below code can do it:
val context = LocalContext.current
val packageManager: PackageManager = context.packageManager
val intent: Intent = packageManager.getLaunchIntentForPackage(context.packageName)!!
val componentName: ComponentName = intent.component!!
val restartIntent: Intent = Intent.makeRestartActivityTask(componentName)
context.startActivity(restartIntent)
Runtime.getRuntime().exit(0)
So... you could write ways to "restart everything", but I am going to strongly suggest not doing that. When building an app, you will run into edge cases. You will hit some failure states that you can't recover from. That happens. But, solving these cases by just "restarting" doesn't actually address the issue and will probably result in wonky and undesirable UX.
I would instead suggest you post here some steps to reproduce and debugging results.
Under what circumstance/flow does this document stop loading?
When it does happen, can you capture the call to Firebase where it is trying to load the document?
If so, what does that call look like?
Is it looking for the document in the correct place?
Can you show an example of the call when it fails and also what the database hierarchy looks like?
Can you show us a snippet of code where this is failing?
Without more information, this sounds more like a race condition - you might be trying to find the document before it is actually created and not handling the error path for when the document is not found. However, we would need to do some debugging to verify.

How to save url and use out of chrome api in Vue.js for chrome extension?

I am currently facing a weird issue with developing a simple chrome extension.
Basically, I want to build an extension that saves the currently focused URL. However, seems like URL is not saved in variables that I defined.
I have tried to use an array to store it, and also a variable.
consoleClick() {
var urlss = []
var getTab = function(tab){
urlss.push(tab)
alert(tab)
};
chrome.tabs.query({'active':true}, function(tabs){
getTab(tabs[0].url)
});
console.log(urlss)
this.$store.commit('addUrl',urlss[0])
console.log(this.$store.state.urls[0])
}
Here, once button is clicked, with "chrome.tabs.query()" I was able to get currently focused url. and I saved it to "urlss", and checked it with console.log(urlss).
I could see the url in console log, however, when I tried to access to url with urlss[0], it says urlss[0] is "undefined" even though I can see that
[]
0: "https://stackoverflow.com/posts/57089954/edit"
length: 1
__proto__: Array(0)
in log. This leads to push "undefined" to my vuex storage.
I also tried to push it to vuex storage right away in chrome.tabs.query(), however it gives me that $store is not defined.
I know that my explanation is pretty messy but I need help from the community! Thanks in advance

Phantomjs no render

I work on a small project with PhantomJS to make screenshot
I use the standard script (http://phantomjs.org/screen-capture.html) everything works perfectly
but if I change the url (this url :https://fr.wikipedia.org/w/index.php?title=Pomme&direction=next&oldid=46779461) screenshot does not work
I do not understand why it does not work...
var page = require('webpage').create();
page.open('https://fr.wikipedia.org/w/index.php?title=Pomme&direction=next&oldid=46779461', function() {
page.render('github2.png');
phantom.exit();
});
I reproduced the issue and it seems like only that single page doesn't work.
Looks like that lemon-loving troll added so many "OOOOO"s that it broke the layout to the point that phantomjs is suiciding and refusing to cooperate.
That's my conclusion. My advice for today is to point your scripts to literally anything else.

Open flash in new page

New to Flash and I am working with Flash 5, actionscript 2.
I have the following code,
b1.onPress = function()
{getURL("http://rosswarner.com/lion.html");
}
I want the page to be opened in a blank page.
I have tried the usual HTML way, no luck, done some looking, no luck so here I am.
Please change the above code to what it has to be if possible.
Thanks.
By Default GetURL uses the parameter "_self"... you need the parameter "_blank"
You can do this by using
getURL("http://rosswarner.com/lion.html";, "_blank");
Other parameters include "_parent" and "_top"

CoffeeScript function can not be found

I have a Rails 3.2.8 application that I have recently upgraded from 3.1, and I have converted all of the original application.js code to CoffeeScript. Most of it is working fine. However, I have a breadcrumb function that I call in several views that is not being found. For right now, I'm just throwing up an alert to see if it is working:
product_breadcrumb = (attr) ->
alert attr
That's in a file called product_search.js.coffee. It is being successfully compiled, and ends up looking like this:
(function() {
var product_breadcrumb;
product_breadcrumb = function(attr) {
return alert(attr);
};
}).call(this);
I guess that's right, I don't know. Anyway, in Firebug I'm getting:
ReferenceError: product_breadcrumb is not defined
Please note that this is after an Ajax call. I don't know why the function wouldn't be available though. It's just a function definition after all. Shouldn't it still be available to the rendered HTML from the Ajax call? I can't understand why the function can't be found.
This needs to be on the global scope, and then you need to call it that way.
You should write:
root = exports ? this
and name your function
root.product_breadcrumb
then you can call it elsewhere as expected.
See this answer for a much lengthier explanation.