I have a local html file on my desktop, when i click on it, if I already have chrome open with several tabs open, it will open my local file in the chrome browser in a new tab.
I want it to open in a separate chrome browser window, so its the only webpage open in that window, no other existing tabs should be open.
I also want to resize the window and ive tried something like this in the header of the html file
<script type="text/javascript">
var myWindow;
function resizeWinTo() {
myWindow.resizeTo(600, 600);
myWindow.focus();
}
window.onload = resizeWinTo;
</script>
but it does not work.
How can i do this, open in a new browser window and then resize that window?
EDIT: Just to clarify, I'm clicking in a html file icon on my desktop, not on a link to an html file within some webpage.
EDIT 2: So ive tried doing what some answer has said below, as a test I have created a simple 'hello world' html page called 'myfile.html' which is saved to my desktop, the code for the file is
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript">
OpenInNewWindow();
var WindowReference;
function OpenInNewWindow()
{
WindowReference = window.open("http://www.google.com",
"DescriptiveWindowName", "resizable=yes,scrollbars=yes,status=yes");
}
</script>
</head>
<body>
<H1> HELLO WORLD! </H1>
</body>
</html>
But if I already have my broswer open (my be minimized) with say some pages open, say bbc.com and cnn.com, so I already have two tabs open. When I double click on 'myfile.html' on my desktop, it just opens a third tab in my existing browser.
But I want a completely new separate browser window to open, how can this be done?
Here is what you can do.
Press win + R to open Run, enter regedit and press enter
Go to HKEY_CLASSES_ROOT\ChromeHTML\shell\open\command
You should see one key, named (Default). Double click this to get an editing pop-up.
Change the key value
From
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -- "%1"
To
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --new-window "%1"
Now whenever you open any saved html page you should be able to see in a new window.
Source
Related
I am having an issue where seemingly the way JavaScript executes is changing depending on whether I open a file from a brand new browser tab (copy-pasting the link in) versus if I open the page by clicking a link from another page.
A summarized version of my code is:
<html>
<head>
<script>
try {
// ...other code...
throw new Error("error");
} catch (e) {
location.href =
"https:\/\/google.com"; // would be "https:\/\/mysite.com"
}
window.close();
</script>
</head>
</html>
If I open this in a brand new tab by copy-pasting the link, the tab will navigate to https://google.com
However, if I open the link via a hyperlink, the new tab closes immediately.
Ideally, I want the redirect to be successful regardless of how the page is loaded.
Would love to understand what's going on here as the above code snippet is from an external library that I can't modify
Appreciate any insight or help!
From MDN:
This method can only be called on windows that were opened by a script using the Window.open() method, or on top-level windows that have a single history entry. If the window doesn't match these requirements, an error similar to this one appears in the console: Scripts may not close windows that were not opened by script.
In other words, a page opened by clicking a link on another site cannot use window.close(). However, if you create it with window.open(), that restriction does not apply and you can use window.close(), which is overriding your redirect. Ctrl clicking on a link to open it in a new tab also satisfies this condition. You can verify that by running window.close() in the devtools console and seeing whether or not it closes the tab.
Hello I am trying to close a WebView window automatically when the page code stop executing. I am adding this to the end of the page
<script type='text/javascript'>
self.close();
</script>
And if I open the webview by clicking on a link in messenger the code works as expected - closes the webview as soon as it gets to it. However, if I open the same page from a link inside an already opened webview, then the code is not triggered and page is not closed.
In both cases I am using one and the same page and the code is added to the bottom of the page. The other code of the page is PHP and HTML
Any idea what is the reason?
The only think that might be is if the webview actually open the link in a new "tab" (not sure if tabs exist in webview) and as a result js cannot close it. This is just a thought.
I am trying to open an external url "https://stackoverflow.com/" on a new tab on opening a page in internet explorer. I have the code for it but when I try to open the page it gives me this dialog box screenshot below. Once I click on Allow Blocked Content then it opens my page in a new tab :
I do not want the user to make any changes to his Internet explorer settings. Is there any changes I can make my code open the "https://stackoverflow.com/" url without the above dialog box ?
<html>
<head>
<script>
function LoadF() {
window.open('https://stackoverflow.com/')
}
</script>
</head>
<body>
<body onload = "LoadF()">
<center><a target="_blank" href="https://stackoverflow.com/">Stack Overflow</a></center>
</body>
</html>
As a shameless copy-paster, It is my duty to notify you that this question was already answered.
To summarize, there are two major points to note:
This bar will only appear when running the page locally, and should not therefore appear when loading the page from a web server.
You can add a line at the top of your code to tell IE that the local file is safe: <!-- saved from url=(0014)about:internet -->
I'm trying to create a pop up.
I host my own website and I would like an image to be displayed as a pop up when the website is opened.
I've tried to write some code:
<head>
<script type="text/javascript">
function openWin(img){
var path = "images/"
window.open(path+img,"mywin","menubar=0,resizable=0,width=200,height=200")
}
</script>
</head>
<body>
open window
</body>
But here i dont want the <a href>. It shows that when I click on it the image opens but I don't want this.
I want the image to just be displayed without the need to click or hover anywhere, and I also want that when I click anywhere outside the image for it to close.
So how do I do this?
Just call the openWin() function in a script tag at the bottom of your html page. Don't associate it with a click or other event, just call the function. The script will run when the page loads, calling the function, which will open a new window on browsers that don't have that turned off.
Possibly, that will then annoy your users and they will go away.
My idea of what am trying to do is
When I open a website on one tab of an internet explorer broweser and click on a link it should open a new tab in the same browser with a pdf page init ... the pdf page has a lot of links which if u try clicking on any of them they should take you back to the old tab where u managed to lunch open the pdf from and keep switching between those two tabs only
I hope the idea is clear .. am trying to do this using html and javascript ... this what I wrote but am still missing a lot here. Thanks in advance for any help provided
this piece here lunches another instant in another window
<html>
<head>
<script>
function son()
{
myWindow=window.open('','','width=500,height=500');
myWindow.document.write(" SON !");
myWindow.focus();
myWindow.opener.document.write("<p> DAD !</p>");
}
</script>
</head>
<body>
<input type="button" value="Open " onclick="son()" />
</body>
</html>
This file is where I have the pdf file built in.
<object data="Test.pdf" type="application/pdf" width="100%" height="100%">
<p>It appears you don't have a PDF plugin for this browser.
you can <a href="Test.pdf">click here to
download the PDF file.</a></p>
</object>
thanks again
In the old days, you could use a window's focus method to bring a window/tab into the foreground. However, abuse (mostly in the form of advertisers' popup windows) has resulted in browsers restricting or disabling that functionality.
If we ignore the PDF part, conceptually, this is a very simple request. First, open a window and hold on to its reference:
var pop = window.open('page.html'); // opens in new tab on most browsers
In the secondary page, switching back to the original was simple:
window.opener.focus(); // no longer works in most modern browsers
And from the first page, to switch back:
pop.focus(); // might work
In my test, I couldn't get IE 9 or Chrome 21 to switch back to the opener tab. In Chrome, I could open the second page, manually switch back to the original tab, and calling pop.focus() did bring the second tab back in focus. (IE did nothing.) I was able to force Chrome back to the opening page by calling window.opener.alert('...'); from the secondary page, but that's an ugly hack.
So it looks like you won't be able to pull this off, at least not reliably.
I'm not sure exactly what you're trying to accomplish (a TOC?), but have you thought about opening two windows? Open one with your links that covers the left-hand side of the screen, and another on the other half with the PDF.
JavaScript does not have APIs for controlling tabs. Therefore, you can't do it.
You can open windows, but you can't control if it will be a tab or window.
One alternative possibility involves NOT opening a second window or tab.
If you open another/replacing page in the current window or tab,
you can use the History object to switch between the two pages.
history.go(-1); //takes you back to previous page
history.go(1); //takes you forward to the page from which you went back.