Open multiple tabs using JavaScript on Bing for Mobile - javascript

I know how to open Multiple Tabs using JavaScript but my solution does not seem not to work on "Bing for mobile".
I'm trying to achieve the following.
Whenever a user clicks on the Call Now button, a call to specified number should be made and the page should redirect to some other page.
For this, the sample code I used is,
<a id="makeCall" onclick="callNRedirect()"> <!-- Target blank, if you want to open in new tab -->
<img alt="Call icon" src="https://static.wixstatic.com/media/14e16f_9f3a8d8153914af3b9ee7c1bb7218506~mv2.png/v1/fill/w_354,h_212,al_c,usm_0.66_1.00_0.01/14e16f_9f3a8d8153914af3b9ee7c1bb7218506~mv2.png" style="width: 170px;" />
</a>
<script type="text/javascript">
let callNRedirect = function(){
makeCall().then(function() {
window.top.location.href = 'http://www.business-insurance-now.com/call2';
});
}
async function makeCall() {
window.open("tel:989898", “_blank”);
}
</script>
The thing is, it is working fine on Webkit based browsers, but Bing for mobile and Microsoft Edge are not working as expected.
Live link for the demo: https://codestroke.blogspot.com/2018/10/samples-samples-everywhere.html
The Bing app won't open the dial app.
The Edge app won't redirect to the page.
Update: Looks like the Edge was blocking the redirection, so it is kinda solved. Not sure of bing though!

Below is a simple example to open 2 links using HREF.
<a href="http://Microsoft.com" onclick="window.open('http://Bing.com');
return true;">multiopen</a>
If you want to open more then 2 links then you can try to refer example below.
<!DOCTYPE html>
<head>
<script>
function demo()
{
window.open('http://yahoo.com');
window.open('http://bing.com');
window.open('http://microsoft.com');
};
</script>
</head>
<body>
multiopen
</body>
</html>

Related

My angular App freezes when the print window is open

I am making an angular app that requires to create a document, open it in a new tab and print a section. I have already achieved this.
The problem is my client want to continue interacting with the app while the print window is still open.
But I have noticed that when this print window is open, the app like it freezes, all click events no longer work until you close this window.
I have tried a few solutions provided here on Stack Overflow but none really works. In one case I tried setTimeout().
Here is my html code:
<!-- Print button-->
<div class="footer-share" (click)="print()">
<button class="btn btn-back"><span class="mdi mdi-printer"></span><span> Drucken</span></button>
</div>
And here is the funtion in my ts file:
print() {
let printContents, popupWin;
printContents = document.getElementById('print-section').innerHTML;
popupWin = window.open('', 'top=0,left=0,height=100%,width=auto');
popupWin.document.open();
popupWin.document.write(`
<html>
<head>
<title>XYZ Records</title>
<style type="text/css" media="print">
#page { size: landscape; }
</style>
<style>${printStyles}</style>
</head>
<body onload="window.print();window.close()">${printContents}
<h2>This is the end!
</h2>
<img src="/assets/images/tempton-logo.png" style="width:60%;padding-top:0%;" alt="homepage" class="dark-logo" />
</body>
</html>`
);
popupWin.document.close();
}
What can I change to make it possible for the user to continue interacting with the app when the print tab is still open?
Remove the html property and value for onload in .write() method. Then, remove the close method directly after the write method use this instead:
popupWin.focus();
popupWin.print();
popupWin.close();
Try to do what was suggested in this other question, it worked for me.
https://stackoverflow.com/a/62808575/7912859
According to the documentation: (https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features) window.open() currently supports features. Hence we can pass noreferrer or noopener as shown below, which does not freeze or block the parent window.
window.open(hostUrl, '_blank', 'noreferrer')

How to clear browsing history using JavaScript?

I am doing a simple project, let us take high secure website. I have 5 different JSP pages. If I started from first JSP page, it is redirecting to second JSP page and so on. In the meanwhile, it should not store those pages in my browser history.
How to clear those browsing history using JavaScript?
Can you try using document.location.replace() it is used to clear the last entry in the history and replace it with the address of a new url. replace() removes the URL of the current document from the document history, meaning that it is not possible to use the "back" button to navigate back to the original document.
<script type="text/javascript">
function Navigate(){
window.location.replace('your link');
return false;
}
</script>
HTML:
<button onclick="Navigate()">Replace document</button>
As MDN Window.history() describes :
For top-level pages you can see the list of pages in the session history, accessible via the History object, in the browser's dropdowns next to the back and forward buttons.
For security reasons the History object doesn't allow the non-privileged code to access the URLs of other pages in the session history, but it does allow it to navigate the session history.
There is no way to clear the session history or to disable the back/forward navigation from unprivileged code. The closest available solution is the location.replace() method, which replaces the current item of the session history with the provided URL.
So there is no Javascript method to clear the session history, instead, if you want to block navigating back to a certain page, you can use the location.replace() method, and pass the page link as parameter, which will not push the page to the browser's session history list. For example, there are three pages:
a.html:
<!doctype html>
<html>
<head>
<title>a.html page</title>
<meta charset="utf-8">
</head>
<body>
<p>This is <code style="color:red">a.html</code> page ! Go to b.html page !</p>
</body>
</html>
b.html:
<!doctype html>
<html>
<head>
<title>b.html page</title>
<meta charset="utf-8">
</head>
<body>
<p>This is <code style="color:red">b.html</code> page ! Go to <a id="jumper" href="c.html">c.html</a> page !</p>
<script type="text/javascript">
var jumper = document.getElementById("jumper");
jumper.onclick = function(event) {
var e = event || window.event ;
if(e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = true ;
}
location.replace(this.href);
jumper = null;
}
</script>
</body>
c.html:
<!doctype html>
<html>
<head>
<title>c.html page</title>
<meta charset="utf-8">
</head>
<body>
<p>This is <code style="color:red">c.html</code> page</p>
</body>
</html>
With href link, we can navigate from a.html to b.html to c.html. In b.html, we use the location.replace(c.html) method to navigate from b.html to c.html. Finally, we go to c.html*, and if we click the back button in the browser, we will jump to **a.html.
So this is it! Hope it helps.
It's not possible to clear user history without plugins. And also it's not an issue at developer's perspective, it's the burden of the user to clear his history.
For information refer to How to clear browsers (IE, Firefox, Opera, Chrome) history using JavaScript or Java except from browser itself?
No,that would be a security issue.
However, it's possible to clear the history in JavaScript within a Google chrome extension. chrome.history.deleteAll().
Use
window.location.replace('pageName.html');
similar behavior as an HTTP redirect
Read How to redirect to another webpage in JavaScript/jQuery?
to disable back function of the back button:
window.addEventListener('popstate', function (event) {
history.pushState(null, document.title, location.href);
});
Ok. This is an ancient history, but may be my solution could be useful for you or another developers.
If I don't want an user press back key in a page (lets say page B called from an page A) and go back to last page (page A), I do next steps:
First, on page A, instead call next page using window.location.href or window.location.replace, I make a call using two commands: window.open and window.close example on page A:
<a href="#"
onclick="window.open('B.htm','B','height=768,width=1024,top=0,left=0,menubar=0,
toolbar=0,location=0,directories=0,scrollbars=1,status=0');
window.open('','_parent','');
window.close();">
Page B</a>;
All modifiers on window open are just to make up the resulting page. This will open a new window (popWindow) without posibilities of use the back key, and will close the caller page (Page A)
Second: On page B you can use the same proccess if you want this page do the same thing.
Well. This needs the user accept you can open popup windows, but in a controlled system, as if you are programming pages for your work or client, this is easily recommended for the users. Just accept the site as trusted.
You cannot clear the browser history. It belongs to the user, not the developer. Also have a look at the MDN documentation.
Update: The link you were posting all over does not actually clear your browser history. It just prevents using the back button.

JavaScript - prerender another page

I'm trying to make a simple gallery page. The website will always reload after pressing "Next" and I want to make some prerender for the next slide (for better performance and faster load).
At the moment I'm using prefetch/prerender options from HTML5, for Chrome and FireFox:
<!DOCTYPE html>
<html>
<head>
<link rel="prefetch" href="index2.html">
<link rel="prerender" href="index2.html">
</head>
<body>
<img src="big_big_buck_bunny.jpg"/>
Next
</body>
</html>
Is there any other way to cache/prerender next page (in this example - index2.html) ? For example using JavaScript? I'm asking about it because I want to make the prerender work also on Opera 12 and IE (8/9).
Maybe use AJAX. In jquery exists .load() method (http://api.jquery.com/load/)
$('#next').click(function () {
$('#container').load('http://fiddle.jshell.net/webdevem/JfcJp/show/');
});
$('#prev').click(function () {
$('#container').load('http://fiddle.jshell.net/webdevem/JfcJp/show/ #specialContent');
});
Here You have example jsfiddle
If your going to navigate to a new page there's no way to precache html. That's what Ajax is for.
You can Ajax in the html, set the document body to the new html. But if the use reloads the page it will be at the wrong place unless you set a #! In the URL. There's not a lot of nice options with IE8.
Cant you see just preload the images, The page itself isnt gona take any time to build...is it?

open a window in background with javascript error in firefox and opera

i'm want to open a file in background with javascript. The code works fine in chrome but in firefox (12) and Opera new windows open in foreground.
Anybody knows what i'm doind wrong?.
Here its code of two files:
father.html:
<html>
<body>
<script>
var son=null;
function openIt(){
son=window.open('son.html','sonpage');
son.blur();
self.focus();
window.focus();
//alert("voy");
return false;
}
</script>
Open
Close
<button type="button" id="play2-video" onclick="son.play()">
play2 video
</button>
<button type="button" id="pause2-video" onclick="son.pausa()">
pause video
</button>
Father Page
</body>
son.html:
<html>
<Head>
<script>
function play(){
alert("Play!");
}
function stop(){
alert("Stop!");
}
</script>
</Head>
<Body>
<h1> Son Page</h1>
</Body>
Thank you!
Firefox will only obey requests to raise a window if a security option
is set, and it's not set by default. Chrome won't pay attention to
focus() requests at all, as far as I can tell. Safari does obey
focus() request.
The specific Firefox setting is in the "Tools -> Options" dialog.
There's a "Content" tab, and in that there's a checkbox for enabling
Javascript. Along with that is an "Advanced" button that brings up
another dialog, wherein one finds a checkbox to allow (or disallow)
the raising and lowering of windows by page code.
read https://stackoverflow.com/a/2533335/643500
Tried to mess with the code -- no joy
The function only needs :
function openIt(){
son=window.open('son.html','sonpage');
window.focus();
return false;
}
Try to redirect back from the opened page to the main one and see if it can be accomplished that way?
Also, look into JQuery, it might handle that with events like http://api.jquery.com/focusout/

JavaScript Reload Page Script

<html>
<head>
<script type="text/javascript">
function show_confirm(){
var r=confirm("Hello or Goodbye?");
if (r==true){
alert("Hello");
window.location.replace("http://www.google.com/");
} else {
alert("Goodbye");
}
}
</script>
</head>
<body>
<input type="button" onclick="show_confirm()" value="Show a confirm box" />
</body>
</html>
I'm learning JavaScript, and I'm using W3School's Tryit Editor, and this code wasn't working like I hoped. I want it to redirect me to google after someone hits 'OK' twice, but it doesn't seem to work. Can someone help me out?
The problem is that the Try-It Editor is using an IFrame. When I try it in Chrome and open up my developer console, I get the following error:
Refused to display document because display forbidden by X-Frame-Options.
This is because what your code is trying to do is change the location of the current frame, not the entire page.
You can do one of three things:
Try your HTML outside of an IFrame and you should get it to work then.
Try using window.top.location.replace("http://www.google.com/"); instead of window.location
If you must change the location of an iframe with JavaScript, you'll have to either do so outside of the frame or make sure it stays within the same domain as the parent document. (You'll notice that window.location.replace("http://www.w3schools.com") works just fine.)

Categories