I want to open a pdf file when page is getting loaded (onload), I done it through calling javascript function on onload action ,I can open a pdf in adobe reader ,but issue is I got new Blank browser-window in addition to adobe file(opened in adobe not in browser)
<html>
<script type="text/javascript">
function windoeOpen() {
var myWindow = window.open(" ", "windowname", "width=200, height=100");
myWindow.location.href = "file:///F:/pdf2.pdf";
}
</script>
<body onload="windoeOpen()">
<code>
........
</code>
</body>
</html>
please give me suggestion how can I close the additional browser blank window.
Note:
but if I open pdf in browser ,it works fine(opened in browser as expected) no addition blank browser.
You just need to specify window.location.href like this:
JavaScript:
<script type="text/javascript">
function windoeOpen()
{
window.location.href = "file:///F:/pdf2.pdf";
}
</script>
HTML:
<body onload ="windoeOpen()">
Related
I have a simple html that will pop out a new email message for people to send out email.
I need to close a window after the email message popped out. I wish to keep only the email message box.
This is my code, but it's not working:
<html>
<head>
<script type="text/javascript">
function mymessage()
{
location.href = "mailto:abc#com.sg?subject=EmailToEnter";
}
</script>
</head>
<body onload="mymessage()">
<script type='text/javascript'>
settimeout('self.close()',1000);
</script>
</body>
</html>
Try something like this:
function mymessage()
{
var d=document.createElement('A');
d.target='_blank';
d.href='mailto:abc#com.sg?subject=EmailToEnter';
d.click();
}
function closewindow()
{
var d=document.createElement('A');
d.href="javascript:window.open('', '_self', '').close()";
d.click();
}
Or you can use window.open
Also use construction like this
window.setTimeout(function(){closewindow();},1000);
Use this
setTimeout("window.close()", 1000);
BUT
This method is only allowed to be called for windows that were opened by a script using the window.open() method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.
https://developer.mozilla.org/en-US/docs/Web/API/Window.close
I have a simple HTML code to print the page. Below is the code:
<!DOCTYPE html>
<html>
<head>
<script>
function printPage()
{
var w = window.open("http://www.sigmaaldrich.com/catalog/CofADocRequest.do?symbol=209104&LotNo=MKBP0842V&brandTest=SIGMA","_self");
window.focus();
window.print();
}
</script>
</head>
<body >
<input type="button" onclick="printPage()" value="print a div!" />
</body>
</html>
What the code does is, it displays a button, on clicking that button it calls a function. The function uses open() to open a new URL in the same page by using the “_self ” parameter.
As we can see in the code, the print() is being called after the call to open method. But in my browser IE11, the print pop is being shown befor loading the page.
Due to this I am not printing the correct page.
Can anybody help me on this.
The problem is that window refers to the current window, which is the original.
By opening a new window in self you replace the page, this is basically a redirect.
And if you open it via popup and print it as w.print() than you run into cross-origin security error.
You could use iframe to this with a proxy as shown here
How do print specific content inside the iframe
and
here
How do print specific content inside the iframe
I don't know too much about programming but somehow I managed to make a pop-up window work. However, I need that from inside the new window (the pop-up one) a button on the pop-up will open a new tab. But I don't need the new tab open in the main browser, I want it open in the same pop-up.
Is this possible?
How can I do it?
I show both the pop-up code and the redirection code that is, at present, sending people to another tab in my web browser, but I need to do it in the same pop-up window that is already open. Here is the code in the pop-up:
<!DOCTYPE html>
<html>
<body>
<p>Click aquí para escuchar Radio Lineage.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
window.open("http://localhost:8000/player/index.html");
}
</script>
</body>
</html>
Here the code of the new tab:
<!DOCTYPE html>
<html>
<body>
.
.
<script type="text/javascript" src="http://hosted.musesradioplayer.com/mrp.js"></script>
<script type="text/javascript">
MRP.insert({
'url':'localhost:8000/stream',
'lang':'es',
'codec':'mp3',
'volume':65,
'autoplay':true,
'buffering':5,
'title':'Radio LineageChile',
'welcome':'Bienvenido a...',
'bgcolor':'#FFFFFF',
'skin':'radiovoz',
'width':220,
'height':69
});
</script>
.
.
</body>
</html>
To open new URL in the same popup window, from your code, I edited to below:
var win = window.open("http://localhost:8000/player/index.html", 'newwin', 'height=200px,width=200px');
after run this line, new popup window will be showed with height=200px, width=200px.
To open new URL in the same popup windown (win), use this line
win.location = "http://www.google.com"/
You can replace google URL by any URL you like.
Hope it helpful!
Good luck.
Johnny
Here the code, just a very small code, that will open the new page as a popup window.Code is working properly.
<!DOCTYPE html>
<html>
<body>
<p>Click the button to open an about:blank page in a new browser window that is 1200px wide and 600px tall.</p>
<button onclick="openWin()">Open Window</button>
<script>
function openWin()
{
var myWindow = window.open("","","width=1200,height=600");
}
</script>
</body>
</html>
<script type="text/javascript">
win = null;
function openPopup(){
win = window.open("http://www.google.com", 'newwin', 'height=200px,width=200px');
}
function openOtherUrl(){
win.location = 'http://www.yahoo.com';
}
</script>
you can use this code, I change URl successfully with it.
Hope it will be helpful for you!
I have a Javascript function that prints the contents of two elements in a webpage. It works in Chrome, Firefox and IE but Safari just brings up an empty window and if I select print, it simply prints a blank page.
Here's my code:
var content = "<!doctype html><html><head>";
content += '<link rel="stylesheet" href="/css/normalise.css" type="text/css" />';
content += '<link rel="stylesheet" href="/App_Themes/CS2011/StyleSheet.css" type="text/css" />';
content += "</head><body>";
//Find the div to insert the rest of the html after
var contractToFind = $(divElement).parent().find("div").get(0);
//Insert rest of code
content += contractToFind.innerHTML;
content += "</body></html>";
//Set up print window and print
var printWindow = window.open('', '', params);
printWindow.document.write(content);
printWindow.document.close();
printWindow.focus();
printWindow.print();
//Close the window
printWindow.close();
Is there a way I can modify my code to allow it to render the page properly in Safari so I can print it? Preferably without using additional plugins.
Edit: Thanks Eric but that didn't work for me. Adding a time delay to the print seems to work well although it's not ideal, even a 10ms delay solves the issue. The line I used was:
setTimeout(this.print, 100);
I found a solution to this problem. The problem resides in the fact that window.print() is not standard for all browser and Safari probably takes a different approach on when triggering it.
I changed a little your code so maybe this solution can't fit your possibility but it works for all browser (tested on Safari, FF, Chrome, IE8).
Note that you need to have a different page for the popup content (I changed the code to retrieve the contract to make a sample for myself, hope you will figure out how to get contract content).
The code:
HTML for the page that opens the popup
<body>
<input type="button" id="popup" value="Open Popup" />
<div id="yourContract">
<div>blablabla</div>
<div>blablabla2</div>
<div>blablabla3</div>
<table>
<tr>
<td>blablabla td1</td>
<td>blablabla td2</td>
</tr>
<tr>
<td>blablabla td3</td>
<td>blablabla td4</td>
</tr>
</table>
</div>
</body>
<script>
$("#popup").click(function(){
var win = window.open("static.html");
});
</script>
HTML for the popup (static.html):
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script>
$.holdReady(true);
$.getScript("print.js", function() {
$.holdReady(false);
});
</script>
</head>
<body>
<script>
var contract = window.opener.$("#yourContract").html(); //change to fit your needs
$("body").html(contract);
</script>
</body>
</html>
JS file (print.js) called by static.html
$(document).ready(function(){
window.print();
window.close();
});
How does it works:
static.html consists of two script section. The section in the body loads via javascript the content in the page.
The section in the head prevent the document to trigger ready status by setting holdReady to true. Then it loads print.js which waits for document to be ready, but we will decide the exact moment because we are preventing it.
After the script is included in the page holdReady is set again to false, triggering the ready status to document and calling the print() and close() functions on the window.
This however occurs after the browser has loaded all the page content, so you will see the preview in the popup page and the print dialog.
Hope this solution is what you need.
I'm trying to use javascript to open a popup window. It works in chrome but not in IE or Firefox.
Here is my code for the head section:
<head>
<script type="text/javascript">
function newPopup(url) {
popupWindow = window.open(
url,'popUpWindow','height=400,width=400,left=550,top=200,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
</head>
And my code in the body section:
<body>
<img src="images/banner/buy.gif">
</body
>
And here is a link to the page:
http://riverswest.com/riverswest-site/ambush-jacket.html
The BUY NOW image what you want to click on.
The issue is your target="". You don't need it if you're going to be using javascript popup code.
This works fine:
<img src="images/banner/buy.gif">