I am trying to figure out how to create a small browser window with no decorations. That is no address bar, no tabs, no bookmarks bar, no minimize/maximize/restore buttons. The only button it has is a small close button. I am trying to create a window that looks like this: dropbox.com/s/xed7p94s1kpnwrg/Smallwindow.png?dl=0
I tried this Javascript, and it is close, but it still leaves the address bar. If I could just get rid of that, it would be great.
<head>
<script class="code" type="text/javascript">
var features = ""
+ "menubar=no,toolbar=no,location=no,personalbar=no"
+ ",status=no,chrome=yes,resizable,centerscreen"
//+ ",width=400" //Width of content window
//+ ",height=200" //Height of content window
+ ",outerWidth=400" //Width of window
+ ",outerHeight=200" //Height of window
+ ",top=500"
+ ",left=600"
;
window.open("http://www.google.com/","_blank",features);
//Can only close windows opened by script.
//window.close();
</script>
</head>
<body>
</body>
The only way I found to do this was with IE (arg!). This html/javascript works:
<html>
<head>
<title>showModalDialog</title>
</head>
<body onload="fnOpen()">
<script>
function fnOpen() {
var sFeatures = "dialogHeight: 500px;";
window.showModalDialog("showModalDialog_target.htm", "", sFeatures)
}
</script>
</body>
Related
I am having a requirement where user can increase (A+) or decrease (A-) using a link or button click to effect the font size of entire content in a SharePoint page. I am using SharePoint Online (Office365) for POC.
I have tried using content editor webpart with html and js as:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function()
{
$('button').click(function()
{
var theElement = $("div").css("font-size");
var textSize = parseFloat(theElement, 10);
var unitOfMeasurement = theElement.slice(-2);
if ( (this).id == "largerTextLink")
{
textSize += 2;
}
else
{
textSize -= 2;
};
$('div').css("font-size", textSize + unitOfMeasurement);
return false;
});
});
</script>
<body>
<div class="font-button">
<button id="smallerTextLink">Smaller Text</button>
<button id="largerTextLink">Larger Text</button>
</div>
</body>
but the above code is not reflecting anything and just the page is refreshed. As a junior developer I don't know whether I am going in a right path.
Is there any way or alternative to solve this requirement?
You could use em's for this.
Here is a good answer/example on a similar question: https://stackoverflow.com/a/16461139/3021549
I have a javascript code which opens a new tab in browser from a list each 50seconds, but the browser will crash after 50tabs or more.
so I want to close new tab and open another one each 50 seconds.
my code is:
<html>
<head>
<script>
function openWindow(){
window.open('"about:blank"');
var x = document.getElementById('a').value.split('\n');
atTime = 0;
for (var i = 0; i < x.length; i++) {
if (x[i].indexOf('.') > 0) {
site = x[i];
if (x[i].indexOf('://') < 0) { site = 'http://' + x[i]; }
setTimeout("window.open('" + site + "')", atTime);
atTime += 50000;
}
}
}
</script>
<style>
html, body
{
height : 99%;
width : 99%;
}
textarea
{
height : 80%;
width : 90%;
}
</style>
</head>
<body>
<textarea id="a"></textarea>
<br>
<input type="button" value="Open Windows" onClick="openWindow()">
<input type="button" value="Clear" onClick="document.getElementById('a').value=''">
</body>
</html>
window.open returns a reference to the new window. Call close on that handle.
https://developer.mozilla.org/en-US/docs/Web/API/window.close
note btw:
FAQ
How can I prevent the confirmation message asking the user whether he wants to close the window?
You can not. New windows not opened by javascript can not as a rule be closed by JavaScript. The JavaScript Console in Mozilla-based browsers will report the warning message: "Scripts may not close windows that were not opened by script." Otherwise the history of URLs visited during the browser session would be lost.
window.close() should work to close tabs you opened (but it's not possible to close a tab you didn't open)
in fact it can't be closed unless it was opened by a script but there is a way to fool the browser into thinking that's the case:
window.open('','_parent','');
then you can use
window.close();
Putting it together:
<script language="javascript" type="text/javascript">
function closeWindow() {
window.open('','_parent','');
window.close();
}
</script>
reference: http://www.yournewdesigner.com/css-experiments/javascript-window-close-firefox.html
to close a firefox tab use
window.close()
this will close the current window.
The following HTML page should open http://www.seznam.cz in a new window and then open the Print dialog to allow printing it.
<html>
<head>
<script>
function printPage()
{
var newWindow = window.open("http://www.seznam.cz", "seznam");
newWindow.document.close();
newWindow.focus();
newWindow.print();
newWindow.close();
}
</script>
</head>
<body>
<a onClick="printPage(); return false;" href="">Print</a>
</body>
</html>
However it only prints a blank page with "about:blank" in the top right and the current date and time in the bottom right corner.
Why doesn't it work as expected?
Try this one.. it will print the Page.You can Change it to Your Requirements.
<input type="button" value="Print" onclick="printPage('content');"></input>
function printPage(id)
{
var html="<html>";
html+= document.getElementById(id).innerHTML;
html+="</html>";
var printWin = window.open('','','left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status =0');
printWin.document.write(html);
printWin.document.close();
printWin.focus();
printWin.print();
printWin.close();
}
The reason is, because you close the window again in you function. Remove
newWindow.document.close();
newWindow.close();
The reason for the blank page is, because you have specified an empty string as href value. Remove the hrefattribute from the tag.
I need to pass some text from the current page to a popup window without going for a server hit. The information (herewith represented by 90) is already available in the parent form (it's like a paragraph-long text which is stored in a hidden variable). I just need to display that as a popup.
Here's what I've tried, this works to some extent but doesn't work if I pass text, instead of a number. My second concern is that the solution kinda looks ugly. Any tips? Thank you.
This is SCCE, you can run it straight in your machine.
<html>
<head>
<title>A New Window</title>
<script type="text/javascript">
var newWindow;
var data;
function makeNewWindow(param) {
data = param;
if (!newWindow || newWindow.closed) {
newWindow = window.open("","sub","status,height=200,width=300");
setTimeout("writeToWindow()", 50); /* wait a bit to give time for the window to be created */
} else if (newWindow.focus) {
newWindow.focus( ); /* means window is already open*/
}
}
function writeToWindow() {
var k = data;
alert(data);
var newContent = "<html><head><title>Additional Info</title></head>";
newContent += "<body><h1>Some Additional Info</h1>";
newContent += "<scr"+"ipt type='text/javascript' language='javascript'> var localVar; localVar = "+ k +"; document.write('localVar value: '+localVar);</scr"+"ipt>";
newContent += "</body></html>";
// write HTML to new window document
newWindow.document.write(newContent);
newWindow.document.close( ); // close layout stream
}
</script>
</head>
<body>
<form>
<input type="button" value="Create New Window" onclick="makeNewWindow('90');" />
</form>
</body>
</html>
Actually, I googled and saw some other approach that uses window.opener.document.forms.element, but here, the window has to know in advance what it has to read from the parent. I need to be able to pass it as it will vary:
<textarea rows="15" name="projectcontent" id="projectcontent" cols="87"></textarea>
<b>View Content</b>
<head>
<title>View Project Content</title>
</head>
<body>
<img src="/images/toplogo.jpg"><br/>
<script language="Javascript">
document.write(window.opener.document.forms['yourformname'].elements['projectcontent'].value)
</script>
<img src="/images/bottomlogo.jpg">
</body>
</html>
use window.opener
From Mozilla Developer Network:
When a window is opened from another window, it maintains a reference
to that first window as window.opener. If the current window has no
opener, this method returns NULL.
https://developer.mozilla.org/en-US/docs/Web/API/window.opener
This way you can have on your original window a callback, and you can notify the window it's load and ready, rather than wait a random delay...
you add a function on the original window:
window.popupReady = function (callbackToPopup) {
callbackToPopup(newData);
}
then the popup can tell the parent window it's ready and pass it a callback to update it with data..
and on the popup try something like:
window.dataReady(newData)
{
alert(newData);
}
document.addEventListener("load", function() { window.opener.popupReady (dataReady); }
I didn't test this code, but I would take such a path as this should ensure the popupWindow is ready for you and is along the spirit of JavaScript.
In your onclick attribute you pass '90' to the function, but the function isn't set up to take an argument. So, change the first line of your function like this:
function writeToWindow(data) {
You don't need the global var data; or the local var k = data;, so get rid of them.
And instead of + k + write + data +.
That should do get your data passed.
Use this code, it works perfectly in all browsers .
#desc = parent text area id
#desc_textarea = popup
$("#desc_textarea").val(window.opener.$("#desc").val())
is it possible to clone an page, javascript and elements in a new popup?
I want to create a popup of a div used like a box of content, all is loaded in javascript
something like
var popup=window.open('', '_blank');
popup.document = this.document;
popup.document.close();
Thanks for your help
I have no idea why you would want to open a copy of the current window and then close it... But here you go:
if(window.name != 'mypopup') {
window.open(document.location.href,'mypopup');
} else {
window.onload = self.close();
}
** Note the window name check.. without it you would just get endless progressoin of windows opening...
<script type="text/javascript">
function popdiv(thediv) {
popwidth = thediv.width;
popheight = thediv.height;
popargs = 'width=' + popwidth + ', height=' + popheight;
popcontents = thediv.innerHTML;
thewindow = window.open('#', 'mypopup', popargs);
thedocument = thewindow.document.open();
thedocument.write = popcontents;
thedocument.close();
}
</script>
<div onclick="popdiv(this);">
Hello,<br />is it possible to clone an page, javascript and elements in a new popup?<br />
<br />I want to create a popup of a div used like a box of content, all is loaded in javascript <br />
Thanks for your help</div>