Javascript refresh method doesn't work in edge? - javascript

I'm currently on a project where I need the page to refresh as soon as the music ends. With chrome and fire fox this code worked perfectly.
setTimeout(location.reload.bind(location), 206000);
However this does not work in edge.
Is there another way of going around it by using javascript not meta tags as this code snippet is in an if else statement.

As #T.J.Crowder said in comments, bind method won't work with location.reload on edge, in order to get cross browsing functionality you need to avoid using it.
Try to using this one instead:
setTimeout(function(){ location.reload(); }, 206000);

Related

Safari refresh prevents jQuery execution

I'm working on a Drupal 7 site, the mobile version of the site which uses Bootsrap as theme.
There is a custom block (created w/ drupal) using jQuery to move some elements on a page, changing some classes and IDs. This block works just fine.
My problem is in a custom module which renders a block. I have some jQuery code in the module's template that is not running on refresh in Safari, but it runs if I go on the address bar and hit "Go" on the keyboard.
edit: IE and Chrome seem to also have a problem, but the jQuery code runs sometimes, doesn't matter if is a refresh, clear cache or whatever.
Nothing special in browser's console.
My jQuery code is supposed to move some elements in the page, on jQuery(document).ready, but is not even working for a simple alert.
p.s.: the jQuery in my custom module's template doesn't have anything to do with the code or the HTML elements affected by the custom block, but I thought maybe it would be good to mention it.
I hope you can understand the issue :)
Thanks.
I was using jQuery(document).ready to execute my code. I changed to jQuery(window).load and now it works fine. The code executes on first page load and on every refresh.
After like two weeks and almost killing myself, this is only thing that worked for ios safari.
$(window).on('load', function () {
setTimeout(() => {
DoLoad();
}, 180);
});
I had a similar problem and tried probably a dozen or more ways to address an issue with Safari. It looks like Safari triggers $(window).on('load',...) jQuery call before DOM completely builds. Or perhaps there is some kind of timing/racing condition. In my case, it was causing an issue, but only after page reloads, only with Safari, and only with a certain cloud provider. Chrome was fine, on prem hosting was fine. The only way which worked somewhat reliably was to introduce an artificial delay via setTimeout() function.
$(window).on('load', function () {
setTimeout(() => {
$.getScript('{{url}}').done(function(){
$("#element").js_function({
arguments
});
});
}, 360);
});

Why doesnt firefox redirect after printing?

First of all, this is a new problem which happens since a few weeks. Currently I'm using FF Version 37.
On multiple sites of our Intranet we use links, that look like this
<a href='some_page.php' onclick='window.print()'>Print</a>
The printing part works fine and normally after the printing is done, the page changes its location. This doesn't happen anymore. We found a temporary workaround, that redirects the page via JavaScript after a timeout of a few seconds. It is hard to find a timeout, that isn't too long for a good user experience and isn't too short so that the redirect doesn't fire.
Does anyone know a solution for this, except rolling back to an older version of Firefox or changing the browser entirely?
This might help
<a href='some_page.php' onclick='doPrint(); return false;'>Print</a>
function doPrint() {
window.print();
document.location.href = "some_page.php";
}
It sounds like a bug if it was redirecting for you before, I'd suggest logging a ticket with Firefox with examples

Why is the javascript psuedo-protocol not working?

So, I'm trying to run on random websites, to play with the javascript psuedo-protocol.
javascript:alert("testtesttest");
And it never works. I've tried 6 websites, and I have no clue what I'm doing wrong. I've tried googling with little success. I'm using the latest version of firefox, and I have javascript enabled.
Firefox disabled it for security reasons, because people were pasting things they were told to in the address bar.
but it still works, if you trigger it from your javascript code.
And in chrome code, I found many cases, a window is initialized with this kind of protocol.
For example if you visit http://www.w3schools.com/jsref/met_win_settimeout.asp
There will be some inside windows to be opened with
javascript:"<html><body%20style='background:transparent'></body></html>"
then later on, the location.href changed to
http://www.w3schools.com/jsref/met_win_settimeout.asp
Any one knows why this kind of change happens, and why it is allowed?
Does it suggest for layer window, the location of the window can be changed to the main page?

JavaScript parent page redirection from iframe

I need to implement parent page redirection from iframe. I know that it is impossible to do in different domains due to browsers security.
However I found that links have target attribute and tried to use it in the following way:
someLink
It works fine if I click this link manually, but I couldn't find cross-browser solution to simulate it using JavaScript.
document.getElementById('testParentRedirect').click();
This works fine in IE, however Firefox and Safari don't know click function :).
I tried to work with jQuery, but for some reason they don't simulate click event for links.
(see following post)
I couldn't find any appropriate solution on Stack Overflow.
Maybe someone could help me in it. I will appreciate it. :)
You can do this in javascript to exit a frame:
window.top.location = "http://google.com";
You can try
top.location.replace( "http://google.com" );
in javascript to "escape" from the frame.
Edit: Using replace is slightly nicer, changed my answer to use that.

iFrame Navigation controlled by JS

I'm using javascript to control the href= field of the iframe located within the page. I am currently using
function DoIFrameNav(object_URL)
{
document.all.additionalText.src="iframeContents.php?id="+object_URL;
selectedEvent = object_URL;
}//end DoIFrameNav
to perform this action. And
onclick=\"DoIFrameNav(".$iCounter.");
to call the action when the user clicks on the table row.
It works perfectly in Firefox and IE6, but nothing else...
Chrome just ignores it...
What would be the universally browser compatible way of doing this?
You should not use document.all in a script that is intended to be cross-browser. Removing that should be your first step. Use document.getElementById() instead. At that point, the code you posted should be acceptable to all major browsers (hopefully).

Categories