Chrome won't change button text in loop - javascript

In firefox all work fine. Using tampermonkey and webextensions (addons). Example of code:
while (pc == 10) {
button3.textContent = "Scraping page " + page + "..."
var url ="https://somelink.to/page?"+page
xhr.open('GET', url, false);
xhr.send();
var json = JSON.parse(xhr.responseText);
obj.push(json.posts)
pc = json.posts.length
if (page == plimit) {
pc = "what you are doing here?"
}
page++  
}
Before used .innerHtml. Also used setTimeout(button3.textContent = "Scraping page "+page+"...",300) . Not work too. I don't know why in firefox work but not in chrome. Also when button clicked it look like freezed (pressed while script running). In Firefox it just clicked.

Related

JavaScript execution works on Chrome and not WordPress

I am running this code in Chrome console dev tools and it works:
const params = new URLSearchParams(window.location.search);
if (window.location.href.indexOf("Phone") != -1) {
$('.test111232 a').attr('href', 'tel:1 ' + params.get('Phone'));
}
if (window.location.href.indexOf("state") != -1) {
$('.test111232234 a').attr('href', 'https://www.example.com/ddd?state=' + params.get('state'));
}
However, when I save the page on WordPress with the Elementor HTML widget, it only changes the first number on the page.
Any ideas?
ok so basically what fixed the error was to add this:
$(document).ready(function()
before the code above, so it looks like this:
<script>
$(document).ready(function() {
const params = new URLSearchParams(window.location.search);
if (window.location.href.indexOf("Phone") != -1) {
$('.test111232 a').attr('href', 'tel:1 ' + params.get('Phone'));
}
if (window.location.href.indexOf("state") != -1) {
$('.test111232234 a').attr('href', 'https://www.example.com/ddd?state=' + params.get('state'));
}
});
</script>
one side point that might be relevant. I had an older version of elementor pro which could be impacting js loading through the html widget.
I had the script opening and closing tags but for some reason it wanted the function and then it worked. Could be that's the way it's suppose to be in the first place.

Popup blocker setting in IE 11 is not working

I am using below code to check popup blocker setting in IE 11. But regardless of any setting "Turn on Pop-Blocker" is checked on or checked off.
Internet Option=>Privacy=> "Turn on Pop-Blocker"
The window.open("/", "", "height=100,width=100"); is opening windows so my else part never get executed. I already spend 2 days but didn't found any solution yet. It seems IE is not working as expected. The same piece of code is working on Chrome, Firefox andenter code here safari perfectly fine.
<script >
var myQueryString = document.location.search;
function detectPopupBlocker()
{
var myTest = window.open("/", "", "height=100,width=100");
if (myTest=='false' || myTest == null || typeof(myTest )=='undefined')
{
window.location.href = '/ChromePopup.html';
myTest.close();
}
else
{
myTest.close();
}
}
"

How to detect page loading error from extension?

Is there a way to detect if tab shows 'error page'?
I mean, for example, if user enters any http://non-existing-url.com or just site is unavailable.
Anything similar to Chrome's webNavigation.onErrorOccured event.
If there is no similar event, perhaps there is a way to check Tab http status (200, 404, 502, 0, etc...)?
Whoops didn't see this topic. Here is how you can do it look for about:neterror load
from: mozillaZine :: Detecting “problem loading page” in firefox
have to read the docuri through the webNavigation of the browser. because the window.location is different
anyways the docuri is real nice when an error it happens. it clearly tells you whats wrong with it in the e parameter.
theese are examples of some docuris that load:
about:neterror?e=dnsNotFound&u=http%3A//www.cu.reporterror%28%27afew/&c=UTF-8&d=Firefox%20can%27t%20find%20the%20server%20at%20www.cu.reporterror%28%27afew.
about:neterror?e=malformedURI&u=about%3Abalk&c=&d=The%20URL%20is%20not%20valid%20and%20cannot%
you can see the first one is dnsNotFound and the second one is malformedURI
var listenToPageLoad_IfProblemLoadingPage = function(event) {
var win = event.originalTarget.defaultView;
var webnav = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation);
//console.log('webnav:', webnav, 'webnav of selectedtab:', window.gBrowser.webNavigation);
var docuri = webnav.document.documentURI; //can also try event.originalTarget.linkedBrowser.webNavigation.document.documentURI <<i didnt test this linkedBrowser theory but its gotta be something like that
var location = win.location + ''; //I add a " + ''" at the end so it makes it a string so we can use string functions like location.indexOf etc
if (win.frameElement) {
// Frame within a tab was loaded. win should be the top window of
// the frameset. If you don't want do anything when frames/iframes
// are loaded in this web page, uncomment the following line:
// return;
// Find the root document:
//win = win.top;
if (docuri.indexOf('about:neterror') == 0) {
Components.utils.reportError('IN FRAME - PROBLEM LOADING PAGE LOADED docuri = "' + docuri + '"');
}
} else {
if (docuri.indexOf('about:neterror') == 0) {
Components.utils.reportError('IN TAB - PROBLEM LOADING PAGE LOADED docuri = "' + docuri + '"');
}
}
}
window.gBrowser.addEventListener('DOMContentLoaded', listenToPageLoad_IfProblemLoadingPage, false);

Safari print with Javascript produces blank when printing an Iframe

I have read up on all issues regarding Safari and blank printing. It seems that a white flash happens, re-rendering the page, and content of the iframe is lost before a print dialog can grab it.
Here is my javascript - It works in all browsers except safari. It brings up the dialog, but prints a blank page.
function PrintPopupCode(id) {
framedoc = document;
var popupFrame = $(framedoc).find("#" + id + '\\!PopupFrame');
var icontentWindow = popupFrame[0].contentWindow || popupFrame[0].contentDocument;
icontentWindow.focus();
icontentWindow.print();
}
function PrintPopup(id) {
setTimeout(function () { PrintPopupCode(id) }, 3000);
}
I have set a timeout, i previously read it would help if the transfer of content took sometime, but it has not helped.
I have also tried with printElement() function on the icontentWindow variable, but it does not support this method.
Print Element Method
This is all in a .js file, and not on the page. I have tried on the page, but the same thing happens.
Help?
Maybe you should try this:
function PrintPopupCode(id) {
framedoc = document;
var popupFrame = $(framedoc).find("#" + id + '\\!PopupFrame');
var icontentWindow = popupFrame[0].contentWindow || popupFrame[0].contentDocument;
icontentWindow.focus();
setTimeout(icontentWindow.print, 3000);
}
function PrintPopup(id) {
PrintPopupCode(id);
}

Bitly API - JavaScript function to open new window

I am using a script i found here to dynamically generate short link for my Tweet buttons and it works perfectly well, but the only thing i cant seem to do is create the link to open in either a new tab or preferably a popup window.
I have tried several variations of the window.location section of the script but so far I've had no luck. If anybody could point me in the right direct I'd be very grateful.
This is the script I am using...
<script>
var TweetThisLink = {
shorten: function(e) {
// this stops the click, which will later be handled in the response method
e.preventDefault();
// find the link starting at the second 'http://'
var url = this.href.substr(this.href.indexOf('http:', 5));
BitlyClient.shorten(url, 'TweetThisLink.response');
},
response: function(data) {
var bitly_link = null;
for (var r in data.results) {
bitly_link = data.results[r]['shortUrl'];
break;
}
var tweet_text = "Text for the Tweet goes here"
window.location = "http://twitter.com/home?status=" + encodeURIComponent(tweet_text + ' ' + bitly_link + " #Hashtag1 #Hashtag2");
}
}
jQuery('.tweetlink').bind('click', TweetThisLink.shorten);
</script>
Many thanks in advance :)
Normally you could just do window.open:
window.open("http://twitter.com/home?status=" + encodeURIComponent(tweet_text + ' ' + bitly_link + " #Hashtag1 #Hashtag2");
BUT, since you are doing an ajax call before this happens, chances are that this window popup will be blocked by the browser, since the window.open command is no longer associated with the click (browsers allow a certain time before a window.open command falls under non-initiated "popup").
A solution would be to first open the window on click (in your shorten function):
var win = window.open('about:blank');
And then redirect in your response function:
win.location = 'http://twitter.com/etc...';
Demo: http://jsbin.com/usovik/1
Perhaps you're looking for
window.open("http://example.com");

Categories