I wanted to open the link from the popup window in same window and then close the popup window.
I got this which was similar to what I was looking for: open the link from the popup window in an external window and then close the original popup window
I tried the solution of that and its closing the popup which I wanted but not redirecting to the specified url.
I have PHP page e.g Page A in which I have used popup window as I mentioned in loading php page with class in javascript
now, on correct.php which opens in popup window, I have a button. For that I used the solution as below which is not redirecting to url :
<input type="button" value="Search" ONCLICK="window.location.href='https://www.google.co.in/';parent.$.colorbox.close();">
what may be the reason for not opening the specified url?
just create two php page user.php and user_admin.php. Copy and paste the code . first run user_admin.php . it will opens user.php using script . after user.php code runs . pop up window will close. function closeBrowser(){ self.close(); } this is script to close pop up window
user_admin.php
<html><head>
</head>
<body onLoad="clickButton()">
<script>
var pop = new Array();
function myFunction() {
pop[0] = window.open("http://user.php");
pop[1] = window.close();
}
</script>
<script>
function clickButton()
{
document.getElementById('button1').click();
}
</script>
<input type="button" id="button1" onClick="myFunction()" value="Button 1" />
</body>
</html>
user.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
function closeBrowser(){
self.close();
}
</script>
</head>
<body onLoad="closeBrowser();">
<!-- Write your code here -->
</body>
</html>
I Hope this will help you . Try it once .
Related
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!
Haven't been programming in JS for a while.
Now, I have following thing:
<html>
<head>
<script language="JavaScript">
function enlarge()
{
window.close();
}
</script>
</head>
<body>
<img src="addresstomyimg.png" onClick="enlarge()" />
</body>
</html>
(it's very simplified, as, in fact, I have WordPress platform with custom JS modifications etc, but in general, this is the idea).
I don't understand why it's not working.
JavaScript cant close the window unless it opened the window.
In your function, replace window.close() with alert('here') and you'll see the function works fine.
If you want your function to close a window, first open one:
<html>
<head>
<script type="text/javascript">
var popup;
function closewin()
{
popup.close();
}
function openwin()
{
popup = window.open('http://www.google.com');
}
</script>
</head>
<body>
<img src="addresstomyimg.png" onclick="openwin()" /> Click to open, then come back here
<br><br>
<img src="addresstomyimg.png" onclick="closewin()" /> Click to close
</body>
</html>
Demo: http://jsfiddle.net/AlienWebguy/pbFha/
If you try running this script using Firefox and use the Firefox's Error Console to look for errors, you can see that the following error gets logged when you run this script.
Scripts may not close windows that were not opened by script.
You can launch the Error Console in Firefox by pressing Ctrl + Shift + J.
On Chrome, your script successfully closes the tab in which it is running.
Note that the right way to use the <script> tag while writing JavaScript is as follows:
<script type="text/javascript">
If you're trying to close the main window, it won't work.
You can only close windows that were opened by JavaScript.
This code works on IE.
<html>
<head>
<script language="JavaScript">
function enlarge()
{
self.close();
}
</script>
</head>
<body>
<img src="addresstomyimg.png" onClick="enlarge()" />
</body>
</html>
How to send a PDF file directly to the printer using JavaScript?
I found two answers in a forum:
<embed src="vehinvc.pdf" id = "Pdf1" name="Pdf1" hidden>
<a onClick="document.getElementById('Pdf1').printWithDialog()" style="cursor:hand;">Print file</a>
and
<OBJECT id = "Pdf2" name="Pdf2" CLASSID="clsid:CA8A9780-280D-11CF-A24D-444553540000" WIDTH="364" HEIGHT="290">
<PARAM NAME='SRC' VALUE="file.pdf">
</OBJECT>
<a onClick="document.Pdf2.printWithDialog()">Print file</a>
But my problem is that it just works on IE, and doesnt work in Firefox or Chrome.
Is there any solution for this?
I think this Library of JavaScript might Help you:
It's called Print.js
First Include
<script src="print.js"></script>
<link rel="stylesheet" type="text/css" href="print.css">
It's basic usage is to call printJS() and just pass in a PDF document url: printJS('docs/PrintJS.pdf')
What I did was something like this, this will also show "Loading...." if PDF document is too large.
<button type="button" onclick="printJS({printable:'docs/xx_large_printjs.pdf', type:'pdf', showModal:true})">
Print PDF with Message
</button>
However keep in mind that:
Firefox currently doesn't allow printing PDF documents using iframes. There is an open bug in Mozilla's website about this. When using Firefox, Print.js will open the PDF file into a new tab.
There are two steps you need to take.
First, you need to put the PDF in an iframe.
<iframe id="pdf" name="pdf" src="document.pdf"></iframe>
To print the iframe you can look at the answers here:
Javascript Print iframe contents only
If you want to print the iframe automatically after the PDF has loaded, you can add an onload handler to the <iframe>:
<iframe onload="isLoaded()" id="pdf" name="pdf" src="document.pdf"></iframe>
the loader can look like this:
function isLoaded()
{
var pdfFrame = window.frames["pdf"];
pdfFrame.focus();
pdfFrame.print();
}
This will display the browser's print dialog, and then print just the PDF document itself. (I personally use the onload handler to enable a "print" button so the user can decide to print the document, or not).
I'm using this code pretty much verbatim in Safari and Chrome, but am yet to try it on IE or Firefox.
This is actually a lot easier using a dataURI, because you can just call print on the returned window object.
// file is a File object, this will also take a blob
const dataUrl = window.URL.createObjectURL(file);
// Open the window
const pdfWindow = window.open(dataUrl);
// Call print on it
pdfWindow.print();
This opens the pdf in a new tab and then pops the print dialog up.
Try this: Have a button/link which opens a webpage (in a new window) with just the pdf file embedded in it, and print the webpage.
In head of the main page:
<script type="text/javascript">
function printpdf()
{
myWindow=window.open("pdfwebpage.html");
myWindow.close; //optional, to close the new window as soon as it opens
//this ensures user doesn't have to close the pop-up manually
}
</script>
And in body of the main page:
Click to Print the PDF
Inside pdfwebpage.html:
<html>
<head>
</head>
<body onload="window.print()">
<embed src="pdfhere.pdf"/>
</body>
</html>
a function to house the print trigger...
function printTrigger(elementId) {
var getMyFrame = document.getElementById(elementId);
getMyFrame.focus();
getMyFrame.contentWindow.print();
}
an button to give the user access...
(an onClick on an a or button or input or whatever you wish)
<input type="button" value="Print" onclick="printTrigger('iFramePdf');" />
an iframe pointing to your PDF...
<iframe id="iFramePdf" src="myPdfUrl.pdf" style="dispaly:none;"></iframe>
More : http://www.fpdf.org/en/script/script36.php
<?php
$browser_ver = get_browser(null,true);
//echo $browser_ver['browser'];
if($browser_ver['browser'] == 'IE') {
?>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>pdf print test</title>
<style>
html { height:100%; }
</style>
<script>
function printIt(id) {
var pdf = document.getElementById("samplePDF");
pdf.click();
pdf.setActive();
pdf.focus();
pdf.print();
}
</script>
</head>
<body style="margin:0; height:100%;">
<embed id="samplePDF" type="application/pdf" src="/pdfs/2010/dash_fdm350.pdf" width="100%" height="100%" />
<button onClick="printIt('samplePDF')">Print</button>
</body>
</html>
<?php
} else {
?>
<HTML>
<script Language="javascript">
function printfile(id) {
window.frames[id].focus();
window.frames[id].print();
}
</script>
<BODY marginheight="0" marginwidth="0">
<iframe src="/pdfs/2010/dash_fdm350.pdf" id="objAdobePrint" name="objAdobePrint" height="95%" width="100%" frameborder=0></iframe><br>
<input type="button" value="Print" onclick="javascript:printfile('objAdobePrint');">
</BODY>
</HTML>
<?php
}
?>
I have a mother page, where is jvscrpt function called openWin() , which opens a new window.
Here is my code:
<html>
<head>
<script type="text/javascript">
function openWin()
{
win=window.open();
win.document.write("<html>");
win.document.write("<head>");
win.document.write("<style type=\"text/css\">");
win.document.write("#media print{.input {display:none}}");
win.document.write("</style>");
win.document.write("</head>");
win.document.write("<body>");
win.document.write("<table align=\"center\">");
win.document.write("<tr><td>result:</td><td>100,--€</td></tr>");
win.document.write("<tr><td colspan=\"2\" id=\"idcko\"><input type=\"button\" value=\"click\" class=\"input\" onclick=\"window.print();\"/></td></tr>");
win.document.write("</table>");
win.document.write("</body>");
win.document.write("</html>");
}
</script>
</head>
<body>
<form>
<input type="button" value="Click me!" onclick="openWin();" />
</form>
</body>
</html>
When I click on button "Click me!" a new window appears, but browser can`t stop loading the page.The page has full functionality,but for example when I want to see source code in Mozilla, I get only a blank page.
Please help...
call
win.document.close();
At the end(after the last write() )
It signals to the browser that the write-process is finished and the document is complete.
but for example when I want to see
source code in Mozilla, I get only a
blank page.
This is because the source was written by your javascript - this is the same as AJAX (you can't view the changes in the source).
Perhaps you would be better of just opening a new page and pass whatever paramters it needs either via a GET/POST or server-side.