JavaScript - Target Blank And Close Popup Window
I have a popup window that has a "link" inside it, which needs to have a target=_blank
but when ever clicked in IE, it stays inside the same window. I tried all of the following, none work PHP Code: <a href='http://www.myurl.net' onclick='window.close();' target='_blank'> <a href="http://www.myurl.net" target="_blank" onClick="javascript:window.close()"> <a href="http://www.myurl.net" target="_blank" onClick="javascript: setTimeout(window.close, 10);"> Thanks Sonny Similar TutorialsHi! I'm new to this, so please bare with me. My terminology may not be up to par. Here's the deal: - I have a button on my Flash site that opens an HTML page in a popup window. In Flash, I open the new window using Actiosnscript 2.0: Code: on (release) { getURL("example1.html", "_blank"); } - Within the popup window are links to other HTML pages. They all open in the same window. I've been using the following to create the links in Dreamweaver: Code: onClick="MM_goToURL('parent','example2.html')" - On each page, I have a "Return to Main Menu" button that should close the popup window. To do this, I have been using: Code: onClick="window.close()" - The problem is that it works differently in each browser, and I can't even get it to consistently close the window in most browsers: Internet Explorer = popup message appears, asking "Are you sure you want to close this window?" or something similar; window closes after clicking "Yes." Safari = Only closes if I'm on the original HTML page. If I click on any of the other links (note that these all open in the same window), those pages' "Return to Main Menu" buttons cease to work. However, if I keep clicking "Back" until I get to the original page, it closes. Opera = Button actually works for each page. Firefox & Chrome = Does not close the window at all. I looked into it and saw that others have used a window.opener to solve similar issues. But, since my popup window is opened using Flash/AS2, I need to find a way around it. I've tried preceding "window.close()" with "window.opener=null" (i.e. - onClick="window.opener=null; window.close()"), but I don't think I'm doing it right because it still doesn't work. I've also seen others use codes that involve functions and variables, but it is beyond my current coding knowledge to implement this. Like I said, I'm sort of new at this. Any advice would be greatly appreciated. Thank you. - PW Hello, I am trying to work on the following: You open the cart page and click the pay now button, that button opens a new window. I am trying to write (and I bet this is easy but I can't seem to get it) a script so that when it detects that window closing to automatically forward the main page to an account page. Is it something like: Code: <script type="text/javascript"> header(Location:"http://www.mysite.com"); if (window.opener.progressWindow) { window.opener.progressWindow.close() } window.close(); } </script> I am no programmer hi Pals, I have a problem regarding the "target" attribute of "a" tag. in my code I use biggerlink jQuery script to give link to p element without come HTML validation problem. I pass the "target" value from PHP to smarty template , but it's not working , When I remove "biggerlink " it works but the link in <p> tag not working . My Tpl file is : Code: {if not empty($campaign)} <div class="securti-adv biggerlink"> {if not empty ($campaign.media)} <a href="{$campaign.url}" {if n($campaign.linkTarget)}target="{$campaign.linkTarget}"{/if} class="thumb"> <img src="{$campaign.image}" title="{$campaign.title1 + $campaign.title2}" alt="{$campaign.title1 + $campaign.title2}" /> </a> {/if} <div class="details"> {if not empty ($campaign.title1) || not empty ($campaign.sub_title)} <a href="{$campaign.url}" {if not empty($campaign.linkTarget)}target="{$campaign.linkTarget}"{/if} title="{$campaign.title1 + $campaign.title2}"> {text2image styleSlug=$campaign.titleStyle1 text=$campaign.title1} {text2image styleSlug=$campaign.titleStyle2 text=$campaign.title2} <span><img src="{$imagesDir}/btn-campaign-meet-security-advisor.png" alt="" title="" /></span> </a> <p> {text2image styleSlug=$campaign.subtitleStyle text=$campaign.subTitle}</p> {/if} </div> </div> <script type="text/javascript" language="javascript"> {literal} $(document).ready(function(){ $('.biggerlink').biggerlink(); }); {/literal} </script> {/if} My plugin code is : Code: (function($) { $.fn.biggerlink = function(options) { // Default settings var settings = { hoverclass:'hover', // class added to parent element on hover clickableclass:'hot', // class added to parent element with behaviour follow: true // follow link? Set to false for js popups }; if(options) { $.extend(settings, options); } $(this).filter(function(){ return $('a',this).length > 0; }).addClass(settings.clickableclass).each(function(i){ // Add title of first link with title to parent $(this).attr('title', $('a[title]:first',this).attr('title')); // hover and trigger contained anchor event on click $(this) .mouseover(function(){ window.status = $('a:first',this).attr('href'); $(this).addClass(settings.hoverclass); }) .mouseout(function(){ window.status = ''; $(this).removeClass(settings.hoverclass); }) .bind('click',function(){ $(this).find('a:first').trigger('click'); }) // triggerable events on anchor itself .find('a').bind('focus',function(){ $(this).parents('.'+ settings.clickableclass).addClass(settings.hoverclass); }).bind('blur',function(){ $(this).parents('.'+ settings.clickableclass).removeClass(settings.hoverclass); }).end() .find('a:first').bind('click',function(e){ if(settings.follow == true) { window.location = this.href; } e.stopPropagation(); // stop event bubbling to parent }).end() .find('a',this).not(':first').bind('click',function(){ $(this).parents('.'+ settings.clickableclass).find('a:first').trigger('click'); return false; }); }); return this; }; })(jQuery); the value of "target" , "_blank" is not work .... I highlight the code part regarding this, please check and give me a solution ASAP. You can mail me at : anes.pa@gmail.com Thanks, Anes Hi, I have parent page with 10 child window and i want to close all child window when click on close session button on parent but first i need to check whether any child window open or not after that action should be done for close the child window. I am using a window.open to trigger a mailto: command. I don't want the window to stay open so I try to close it right after. The default email client launches correctly, but the window stays open and I get the following Javascript error: Unable to get value of the property 'close': object is null or undefined Code: Code: var win = window.open(mailto_link,'emailWindow'); win.close(); I am having a heck of a time closing this popup window when i logoff the site. i open it by Code: shoutwindow = window.open("<?=$MY_LINK_ROOT?>/shoutbox/minichat.php", "shoutwindow", "location=0,status=0,scrollbars=0,menubar=0,resizable=0 width=300,height=310"); when i click logoff the site i want the popup to close also here is the logoff php Code: session_start(); //only for testing will remove this if(!shoutwindow.closed) { echo "window open"; self.close(); //shoutwindow.close (); // also tried both these didnt work // window.close(); } else { echo "Window already closed"; } mysql_close($link); unset($_SESSION['Sess_UserId']); // Unset all of the session variables. session_unset(); // Finally, destroy the session. session_destroy(); echo "<script> location.href='$MY_LINK_ROOT'</script>"; exit; ?> what am i missing here lol ? thanks UPDATE: i just had an idea, can i mix a href and an onClick together so that both are executed like this (i never tried it before) Code: the reason i use self.close is because i heard that it always closes the child not the parent. <a href="logoff.php" onClick="self.close()" return:true;>Log Off</a> the return true will make it execute the href as well right? Unable to close the popup. Have done the best I can Can someone please help me here. Would also like to be able to display without scrolling bars Here is the link http://www.videowebmastery.com/video...ters/index.htm Cheers Trying to get this link to close window onclick, can I even do it? I'm just not seeing how, but I'm probably missing the obvious... Code: <img usemap="#map3" id="shapeimage_5" src="Notice2_files/shapeimage_5.png" style="border: none; height: 49px; left: -67px; position: absolute; top: -3px; width: 261px; z-index: 1; " alt="December 2011 notice" title="" /><map name="map3" id="map3"><area href="https://docs.google.com/open?id=0BwxS6NVXBkCvMTZiMTc1MzYtNDA1Yi00YzRjLWFjNDktNGI5ZDVjYTJkNTkw" title="https://docs.google.com/open?id=0BwxS6NVXBkCvMTZiMTc1MzYtNDA1Yi00YzRjLWFjNDktNGI5ZDVjYTJkNTkw" alt="https://docs.google.com/open?id=0BwxS6NVXBkCvMTZiMTc1MzYtNDA1Yi00YzRjLWFjNDktNGI5ZDVjYTJkNTkw" coords="67, 3, 258, 46" onclick="window.open(this.href); return false;" onkeypress="window.open(this.href); return false;" /></map> Hey guys, Been searching on google for two days now, without a valid answer. I'm NEW to javascript, so I need some good help on this haha. I am using the following little piece of code to open a popup window: Code: <SCRIPT LANGUAGE='JAVASCRIPT' TYPE='TEXT/JAVASCRIPT'> <!-- var win=null; function NewWindow(mypage,myname,w,h,pos,infocus){ if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;} if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;} else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20} settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings); win.focus();} // --> </script> The actual link to open the popup is like this: Code: <a href="javascript:NewWindow('upload.php','popup','550','252','center','front');">Open the popup</a> What I am opening is, an upload page to upload an image (PHP / AJAX). Once the upload is complete and I close the window, I need the parent window (the index page which the link to open the popup is on) to be refreshed, so you can see that the file has been successfully uploaded. Does anyone have a clue how I would fix this? If I need to use another code to open the popup, that's fine, I just need help on how to fix this, since I haven't been able to find the answer myself. Thanks in advance! I'm implementing that stupid Cookie Law thing here in the UK, but I can't get the popup to close on click in IE. Every other browser is working fine. Any one know the fix? Code: <style type="text/css"> <!-- #eucookielaw { display:none } #note { position: fixed; z-index: 101; bottom: 0; left: 0; right: 0; background: #98FB98; text-align: center; vertical-align: middle; color: #2C2C2C; line-height: 2.5; overflow: hidden; -webkit-box-shadow: 0 0 5px black; -moz-box-shadow: 0 0 5px black; box-shadow: 0 0 5px black; } #note a { color: #2C2C2C; } #note img { vertical-align: middle; } #close { cursor: pointer; } @-webkit-keyframes slideDown { 0%, 100% { -webkit-transform: translateY(-50px); } 10%, 90% { -webkit-transform: translateY(0px); } } @-moz-keyframes slideDown { 0%, 100% { -moz-transform: translateY(-50px); } 10%, 90% { -moz-transform: translateY(0px); } } .cssanimations.csstransforms #note { -webkit-transform: translateY(-50px); -webkit-animation: slideDown 2.5s 1.0s 1 ease forwards; -moz-transform: translateY(-50px); -moz-animation: slideDown 2.5s 1.0s 1 ease forwards; } .cssanimations.csstransforms #close { display: none; } --> </style> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> function SetCookie(c_name,value,expiredays) { var exdate=new Date() exdate.setDate(exdate.getDate()+expiredays) document.cookie=c_name+ "=" +escape(value)+";path=/"+((expiredays==null) ? "" : ";expires="+exdate.toUTCString()) } </script> <div id="eucookielaw" > <div id="note"> <img src="/images/cookie_sm.png" alt="Cookie" border="0"> This Site Uses Cookies. :: <a rel="nofollow" href="/terms.php">Learn More</a> :: <a id="close"><u>Close this Message</u> <img src="/images/close_sm.png" alt="Close" border="0"></a> </div> <script> close = document.getElementById("close"); close.addEventListener('click', function() { note = document.getElementById("note"); note.style.display = 'none'; }, false); </script> </div> <script type="text/javascript"> $("#eucookielaw").show(); SetCookie('eucookie','eucookie',365*10) </script> Example he No Claims Discount Insurance | Car, Home, Bike and Health No Claims Bonuses I have the code below in my popup window which currently brings up a blank page in the background as the main window. Instead I want the popup to come up but the original page I left is in the background as the main window. Does anyone know how I can do that with the code I currently have. Code: <html> <head> <title>JavaScript Popup Example 3</title> </head> <script type="text/javascript"> function poponload() { testwindow = window.open("", "mywindow", "location=0,status=0,scrollbars=0,width=350,height=400"); testwindow.moveTo(0, 0); testwindow.document.write('<h1>Get outta here!</h1><a href="javascript:void(0);" onclick="window.opener.history.go(-1); self.close();">Parent back button</a>'); testwindow.focus(); } </script> <body onload="javascript: poponload()"> </body> </html> How to center javascript popup without css? Cant get close button working(wrong position and dosen't close popup). Code: <script language="javascript"> function openPopup(a, b, c){//a = url, b = width, c = height var pOverlay, pContent, pClose; pOverlay = document.createElement('div'); pOverlay.className = 'popupOverlay'; pContent = document.createElement('div'); pContent.className = 'popupContent'; pClose = document.createElement('div'); pClose.className = 'popupClose'; document.body.appendChild(pOverlay); document.body.appendChild(pContent); var myRequest = new ajaxRequest(); myRequest.open('GET', a, true); myRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); myRequest.send(null); myRequest.onreadystatechange = function(){ if(myRequest.readyState == 4 && myRequest.status == 200){ pContent.innerHTML = myRequest.responseText; } } } </script> Code: <style type="text/css"> .popupOverlay { background: #000000; opacity: 0.8; position: fixed; top: 0%; left: 0%; width: 100%; height: 100%; z-index: 1001; } .popupContent { background: #333333; border: 2px solid #DDDDDD; box-shadow: 0px 0px 20px #999999; border-radius: 3px; position: absolute; top: 50%; left: 50%; padding: 5px; z-index: 1002; overflow: auto; word-wrap: break-word; color: #FFFFFF; /*height: 300px; width: 500px;*/ } .popupClose { background: url('images/closePopup.png') no-repeat; width: 32px; height: 32px; cursor: pointer; } </style> I have a few banners and forms that I wish to open in a new tab not the same window or a new window. I have tried the deprecated Code: target="_blank" but even that opens a new window. I have done some research on google and came up with CSS code: Code: form[target] { target-name: new; target-new: tab; } a[target] { target-name: new; target-new: tab; } This however does not work and opens in the same window. When using the CSS I remove the inline target. Any Ideas on how to fix this? Hi to all, I am not an IT person but interested in discovering javascript programming. I have here codes for alarm clock but the thing is that I want the specified target URL to open in new window. If and only if I have a background with this programming maybe I could do it. Please guys, help me with this one. I found this code from javascriptkit (credit to them) <html> <head> <style type="text/css"> #jsalarmclock{ font-family: Tahoma; font-weight: bold; font-size: 12px; } #jsalarmclock div{ margin-bottom: 0.8em; } #jsalarmclock div.leftcolumn{ float: left; width: 150px; font-size: 13px; background-color: lightyellow; clear: left; } #jsalarmclock span{ margin-right: 5px; } </style> <script type="text/javascript"> /*********************************************** * JavaScript Alarm Clock- by JavaScript Kit (www.javascriptkit.com) * This notice must stay intact for usage * Visit JavaScript Kit at http://www.javascriptkit.com/ for this script and 100s more ***********************************************/ var jsalarm={ padfield:function(f){ return (f<10)? "0"+f : f }, showcurrenttime:function(){ var dateobj=new Date() var ct=this.padfield(dateobj.getHours())+":"+this.padfield(dateobj.getMinutes())+":"+this.padfield(dateo bj.getSeconds()) this.ctref.innerHTML=ct this.ctref.setAttribute("title", ct) if (typeof this.hourwake!="undefined"){ //if alarm is set if (this.ctref.title==(this.hourwake+":"+this.minutewake+":"+this.secondwake)){ clearInterval(jsalarm.timer) window.location=document.getElementById("musicloc").value } } }, init:function(){ var dateobj=new Date() this.ctref=document.getElementById("jsalarm_ct") this.submitref=document.getElementById("submitbutton") this.submitref.onclick=function(){ jsalarm.setalarm() this.value="Alarm Set" this.disabled=true return false } this.resetref=document.getElementById("resetbutton") this.resetref.onclick=function(){ jsalarm.submitref.disabled=false jsalarm.hourwake=undefined jsalarm.hourselect.disabled=false jsalarm.minuteselect.disabled=false jsalarm.secondselect.disabled=false return false } var selections=document.getElementsByTagName("select") this.hourselect=selections[0] this.minuteselect=selections[1] this.secondselect=selections[2] for (var i=0; i<60; i++){ if (i<24) //If still within range of hours field: 0-23 this.hourselect[i]=new Option(this.padfield(i), this.padfield(i), false, dateobj.getHours()==i) this.minuteselect[i]=new Option(this.padfield(i), this.padfield(i), false, dateobj.getMinutes()==i) this.secondselect[i]=new Option(this.padfield(i), this.padfield(i), false, dateobj.getSeconds()==i) } jsalarm.showcurrenttime() jsalarm.timer=setInterval(function(){jsalarm.showcurrenttime()}, 1000) }, setalarm:function(){ this.hourwake=this.hourselect.options[this.hourselect.selectedIndex].value this.minutewake=this.minuteselect.options[this.minuteselect.selectedIndex].value this.secondwake=this.secondselect.options[this.secondselect.selectedIndex].value this.hourselect.disabled=true this.minuteselect.disabled=true this.secondselect.disabled=true } } </script> <body> <form action="" method=""> <div id="jsalarmclock"> <div><div class="leftcolumn">Current Time:</div> <span id="jsalarm_ct" style="letter-spacing: 2px"></span></div> <div><div class="leftcolumn">Set Alarm:</div> <span><select></select> Hour</span> <span><select></select> Minutes</span> <span><select></select> Seconds</span></div> <div><div class="leftcolumn">Set Alarm Action:</div> <input type="text" id="musicloc" size="55" value="http://www.youtube.com/watch?v=v1zY_tV5kaQ" /> <span style="font: normal 11px Tahoma">*Location of page to launch</span></div> <input type="submit" value="Set Alarm!" id="submitbutton" /> <input type="reset" value="reset" id="resetbutton" /> </div> </form> <script type="text/javascript"> jsalarm.init() </script> </body> </head> </html> Help me please. Ive been searching for results for this one for 3 months. this is quite embarrasing as i've done it before, but oh well... trying to close a window that is opened with a built-in dreamweaver function called MM_openBrWindow(). trying to use this code: PHP Code: if ($OutsideVisitors == "false") { echo '<center><strong><em><font size="4">THERE HAVE BEEN NO VISITORS TO THE WEBSITE TODAY... </font></em></strong><br><br><input name="closeme" type="button" id="closeme" value="Close Window" onclick="Window.Close()"; /></center>'; } i have also tried: PHP Code: onclick=javascript:Window.Close() it's just not behaving for me. any hints anyone? thanks a bunch! (the BrWindow() function in DW does open a popup window, so I think the js close() should work. if i remember right, a popup window is a prereq for that function to even work...) I am trying to execute a simple window.close function to be used in IE8 and IE9, and window.close() doesn't seem to be working. Are there any known fixes?
I know next to nothing about javascript and I don't even know if this is possible. I need to target window.location.href to an iframe on a different page. So, right now, the piece of the code that redirects the browser looks like this: Code: window.location.href='http://www.somewhere.com/'; Works great, brings it up in the same browser window. So now I need to modify the code so it goes to a different page and brings that page up in a specified iframe. I hope this makes sense. I really need help. And if it is not possible, I just need to know to abandon all hope. Hi, I'm kinda hoping this is possible but haven't found any reference to it... I have a parent page that opens a popup on click that launches a sidebar navigation on the right of the screen and resizes the parent page. What I am wanting to do is create a second popup (approx 250px high) that opens below the navigation (which is only around 600px high) but I have noticed that even when you have no status bar in the popup windows, they can still end up overlapping because of additional tools or plugins that the viewer has in their browser. Is there any way to get the popups to butt up against each other instead of overlapping? More like a relative popup? Any assistance would be appreciated. :-) I have a form that lets users click on date time value that is a link. When the link is clicked, a pop up opens up allowing the user to change the date and time. When they submit the date/time change form, the pop up is supposed to close and the date/time i the original form should be updated. This works in IE, but not FireFox. Inital form code: Code: function openTimeWin(windowURL, windowname) { var strHelpOptions = 'toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=320,height=230'; mywindow = window.open(windowURL, windowname,strHelpOptions); mywindow.moveTo(5,5); mywindow.focus(); } Code: <A HREF="javascript:openTimeWin('CallLoggerTime.cfm?SCDate=#URLEncodedFormat(DateFormat(StartCall,'mm/dd/yyyy'))#&ECDate=#URLEncodedFormat(DateFormat(EndDefault,'mm/dd/yyyy'))#&SCTime=#URLEncodedFormat(TimeFormat(StartCall,'h:mm:ss tt'))#&ECTime=#URLEncodedFormat(TimeFormat(EndDefault,'h:mm:ss tt'))#','TimeWin')">#TimeFormat(StartCall,"h:mm:ss tt")#</a> Pop up window relevant code: Code: <script language="Javascript"> opener.ThisForm.StartCall.value = "#newStart#"; opener.ThisForm.EndCall.value = "#newEnd#"; opener.catchdummy.prematureflag.value=0; opener.ThisForm.submit(); self.close(); </script> Anyone know what's up? Thanks! Been trying for three days to find a way to self close a FF window. The window is opened from a link on a board, and its only purpose is to run an onLoad script that launches a popup window, after which I need it to close itself. There are any number of ways to do this in IE, but nothing works in FF - the parent window remains open. Seems ridiculous that something so simple can't be done. Any help would be appreciated. Thx. |