JavaScript pop-up window AD code

Source: Internet
Author: User

window.open the command to eject a new window;

The filename of the ' page.html ' pop-up window;

' NewWindow ' pop-up window name (not filename), not required, available null ' instead;

height=100 window height;

width=400 window width;

The pixel value of the Top=0 window from the top of the screen;

The pixel value of the left=0 window from the left side of the screen;

Toolbar=no whether the toolbar is displayed, yes for display;

Menubar,scrollbars represents the menu bar and scroll bar.

Resizable=no whether to allow changes to the window size, yes to allow;

Location=no whether the address bar is displayed, yes is allowed;

Status=no whether the information in the status bar is displayed (usually the file is open), yes to allow;

Basic changes

The code is as follows Copy Code

<script language= "JavaScript" >
<!--
window.open (' page.html ', ' newwindow ', ' height=100, width=400, Top=0, left=0, Toolbar=no, Menubar=no, Scrollbars=no, Resizable=no,location=no, Status=no ')
Write a line
-->
</SCRIPT>

Bounce a full-screen window

Join fullscreen

The code is as follows Copy Code

<script language= "JavaScript" >
<!--
window.open (' page.html ', ' newwindow ', ' fullscreen ')/full screen, natural other conditions will be ineffective
-->
</SCRIPT>


Access to pop-up menus/windows

1. window.open new browser window: Focus to a new window.


Referenced from: quickmode-popups

The code is as follows Copy Code
function Popitup (URL) {
Newwindow=window.open (URL, ' name ', ' height=200,width=150 ');
if (Window.focus) {
Focus to new Window
Newwindow.focus ();
}
To block the default behavior of triggers
return false;
}

<iframe/> Created window: Debugging for a long time, IE8/9 need to wait for the IFRAME after the successful settimeout Hack;firefox can not use Ifrcontentwindow.focus (), can only use Ifram E.focus (). Combined, this code is needed:

The code is as follows Copy Code


For all except Firefox
settimeout (function () {
F.contentwindow.focus ();
}, 50);

Hack for Firefox
Navigator.userAgent.toLowerCase (). IndexOf (' Firefox ')!==-1 && f.focus ();

No pop-up windows after refreshing

We can use cookies to control it.
First, add the following code to the <HEAD> area of the homepage HTML:

The code is as follows Copy Code
<script>
function Openwin () {
window.open ("page.html", "" "," width=200,200 ")
}
function Get_cookie (Name) {
var search = Name + "="
var returnvalue = "";
if (Documents.cookie.length > 0) {
offset = documents.cookie.indexOf (search)
if (offset!=-1) {
Offset + = Search.length
End = Documents.cookie.indexOf (";", offset);
if (end = = 1)
end = Documents.cookie.length;
Returnvalue=unescape (documents.cookie.substring (offset, end))
}
}
Return returnvalue;
}
function Loadpopup () {
if (Get_cookie (' popped ') = = ") {
Openwin ()
Documents.cookie= "Popped=yes"
}
}
</script>

Then, with <body onload= "Loadpopup ()" > (note not openwin but Loadpop!) Replace the main page in the original <BODY> this sentence can be. You can try to refresh the page or re-enter the page, and the window will never pop again.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.