window.open(url) fails to download the pdf file - javascript

I am trying to open a URL, which points to a PDF, using window.open(url). In IE, the popup window flashes and nothing happens afterwords. When I access the same url directly using IE, PDF opens up perfectly.
In the HTML below, when I click on Link, I get the PDF but window.open fails. Moreover, if I provide a direct link of PDF in window.open that also works perfectly. Could any body shed some light on this?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
Link
<script>
url = "http://phx.corporate-ir.net/External.File?item=UGFyZW50SUQ9NDk2Mjl8Q2hpbGRJRD0tMXxUeXBlPTM=&t=1";
window.open(url);
</script>
</BODY>
</HTML>
Thanks

Most browsers block window.open when is called without user interaction in order to avoid popup advertisements.
Why are doing this anyway? Instead you should link directly to the PDF in the original document, where you can use target="_blank" if it must be in a new window. (Keep in mind, that there are users that don't like it if websites open new windows).

This may just be my convention, but I always use window.open() like this:
var win = window.open(url);

Related

how to open a html file by onclick? [duplicate]

I want to open a local HTML file through Javascript using:
window.open ("file://C:/Users/wins/Desktop/exclusiveWordpress.html","mywindow");
But it is opening a new window with a blank page as we used to get when URL is not specified. How do I achieve this?
This worked for me fine:
File 1:
<html>
<head></head>
<body>
CLICK ME
</body>
<footer></footer>
</html>
File 2:
<html>
...
</html>
This method works regardless of whether or not the 2 files are in the same directory, BUT both files must be local.
For obvious security reasons, if File 1 is located on a remote server you absolutely cannot open a file on some client's host computer and trying to do so will open a blank target.
window.location.href = 'file://///fileserver/upload/Old_Upload/05_06_2019/THRESHOLD/BBH/Look/chrs/Delia';
Nothing Worked for me.
First, make sure that the source page and the target page are both served through the file URI scheme. You can't force an http page to open a file page (but it works the other way around).
Next, your script that calls window.open() should be invoked by a user-initiated event, such as clicks, keypresses and the like. Simply calling window.open() won't work.
You can test this right here in this question page. Run these in Chrome's JavaScript console:
// Does nothing
window.open('http://google.com');
// Click anywhere within this page and the new window opens
$(document.body).unbind('click').click(function() { window.open('http://google.com'); });
// This will open a new window, but it would be blank
$(document.body).unbind('click').click(function() { window.open('file:///path/to/a/local/html/file.html'); });
You can also test if this works with a local file. Here's a sample HTML file that simply loads jQuery:
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
</head>
<body>
<h5>Feel the presha</h5>
<h3>Come play my game, I'll test ya</h3>
<h1>Psycho- somatic- addict- insane!</h1>
</body>
</html>
Then open Chrome's JavaScript console and run the statements above. The 3rd one will now work.

How to do redirect to others browser from IE?

<!DOCTYPE html">
<html lang="en">
<head>
<meta charset="utf-8">
<title> Redirecting EWS Manager to Chrome </title>
<h1>Browser Redirecting ......</h1>
<script type="text/javascript">
{ varshell = new AciveXObject("WScript.Shell");
shell.run("Chrome //new Link here//");
window.location.replace("#old link the default browser"):}
setTimeot("pageRedirect()",3000);
</script>
</head?
</html>
Above code is for redirecting and named as redirect.html. But it only works when I open my website in IE so that it will redirect to Chrome. But If I open in Chrome, it will only shows Redirecting to Chrome. It does't work in Chrome, It only works in IE. Opening in IE and redirecting to Chrome is works. But reopening in Chrome doesn't work. May I know why and can you please show me a way to fix it?
echo " <tr><td class=\"left_padding\"><a class=info href=\"http://sgewsweb.amk.st.com:8080/web/system/usermgr7/redirect_edge.html\" >User Manager<span>EWS Administrator</span></a></td></tr>";
This link is from my default homepage. When I click to the tab, it opens in Chrome. Some says I have to do with onclick function but I have no idea how to use it. Can you please fix it for me?
enter image description here
When I open Chrome, it pperars like this.
You can try redirecting through header location in php. It will work in all browsers. However, it needs to be placed before any html output.
<?php header('Location: newlink.php'); ?>

window.close not closing window in HTA application

In my HTA application I'm using a JavaScript calendar window, it opens using window.open() and closed using window.close(), when the user clicks on one of the dates. This calendar works fine on multiple browsers and versions over more than 10 years. It even works in HTA applications most of the time.
However on specific workstations running IE11. The window.close() command is simply ignored, resulting in the window left open. On other IE11 workstations it works fine. I figured that turning off the "Enable Protected Mode" checkbox on IE11, Internet Options, Security tab resolves the problem on one of the problematic workstation. However, other workstations works fine with this setting turned on and turning off this setting is not an acceptable solution.
Code sample which reproduces the problem:
HTA application
<HTML>
<HEAD>
<HTA:APPLICATION ID="OpenCloseExample" BORDER="thick" BORDERSTYLE="complex"/>
<TITLE>Open Close HTA container</TITLE>
</HEAD>
<iframe width="1024px" height="768px" src="http://localhost:28080/openclose.html"/>
</HTML>
openclose.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Main Page</title>
<script src="openclose.js"></script>
</head>
<body>
open
</body>
</html>
openclose.js
var win;
function openWindow() {
win = window.open("", "_blank", 'width=250,height=250,status=no,resizable=no,location=no,top=100,left=100');
win.document.writeln("<html><head><script src='openclose.js'></script></head><a href='#' onclick='javascript:window.opener.closeWindow()'>close</a></html>");
}
function closeWindow() {
win.window.close();
}
I can't see this working in any IE with any settings. The problem is this string: <script src='openclose.js'></script>. That is, a literal ending script tag in a string works as an ending script tag on a page, when HTML parser will find it. This means, that your script was never loaded.
To fix this, you've to break the literal tag, for example like so:
<script src='openclose.js'><\/script>
Since you have pointed out that IE11 is causing the JS not to work, you can force IE to render in an older version very easily.
<meta http-equiv="X-UA-Compatible" content="IE=9">
This meta tag is very popular amongst HTA applications for utilizing JS/ActiveX methods/properties within specific IE versions (most of them being deprecated).
For more information, visit the X-UA-Compatible Tag Wiki
Hope this helps
I figured this out eventually.
Changing:
open
to:
open
Has resolved the problem

Change Chrome extension tab title

My Chrome extension create a tab using the API
chrome.tabs.create({
'url': other_extension_url
})
The url is the the url of another extension and looks like:
chrome-extension://ext_id_goes_here/url
I would like to change the the title of the newly created tab (document.title).
I tried to do it using content script but as far as I understand there is no way to use content script with url that looks like chrome-extension://
Is there an any other way to do that?
No, there is no way to do that, since security model will not allow you to access other extensions' pages.
The title is set by the document itself, and cannot be modified by tabs API.
Here is one way to do it.
<html>
<head>
<title>My title</title>
</head>
<body style="margin:0;padding:0;overflow:hidden;">
<iframe style="width:100%;height:100%;" src="chrome-extension://extension_id/page.html"></iframe>
</body>
</html>
Note I haven't tried it from within an extension html but it did work from a html file:// opening an extension page in the iframe.
Based on this, you can have a single "wrapper" page that receives the title and the iframe url as a url parameter and updates its DOM to change the title and iframe src.

using window.location.href to point to javascript enabled page

I am creating a personal website.So,its a very lightweight website!
The website uses jquery heavily.So if target browser doesn't have javascript enabled,my website would not work.
To resolve this issue I used this html
<html>
<head>
<script>
window.location.href="javascriptEnabled.html";
/*Since javascript is enabled redirect to javascript based page*/
</script>
</head>
<body>
Showing Static Website since javascript is not enabled..
</body>
</html>
As you can see,I am redirecting to javascript enabled page if the target browser supports it.
But if javascript is not enabled,the script would not work and then static html would be loaded which is in body tag!
I have two questions.
1>Is this the best way to resolve javacript-no javascript issue browser issue?
2>If I use window.location.href and the browser is javascript enabled,would it download the full page or would it stop at window.location.href?
To keep things simple, yes it's an OK idea. You can load content with <noscript> tags
As soon as the browser hits that window.location.href it will start redirecting, but it will still download all DOM. Browsers download all Document then it will start to render.
You can use: <body onload="document.body.style.display = 'none';"> to hide it's contents until redirect occurs.

Categories

Resources