Target="_blank" opening in old window - javascript

I have an asp.net 2.0 website. On one page - let's call it "P1", I have a button that opens a new window using javascript - let's call the new window "P2".
<script type="text/javascript">
function openMapEditor() {
var editor = window.open('<%= Page.ResolveURL("~/imgmap/MapEditor.aspx") %>', '', 'scrollbars=yes, resizable=yes, width=965, height=800');
var timer = setInterval(function() {
if(editor.closed) {
clearInterval(timer);
__doPostBack('','');
}
}, 1000);
}
</script>
...
<asp:Button ID="cmdEditMap" runat="server" CssClass="cmdbutton" Text="Upload Image" OnClientClick="openMapEditor(); return false;" />
Clicking on the button opens an actual new window in Chrome as I had hoped.
In the new window, I have a link to open another page.
<a name="img_href_check" href="http://facebook.com/fn" target="_blank" onclick="return (new RegExp('^https?://+')).test(this.getAttribute('href'));">Check</a>
What I was hoping was that the page would open in a new tab in P2, but what actually happens is that it is opened in a new tab P1.
How can I make it so that the page opens in a new tab in P2?
Thanks in advance!

Related

How to window.open in a new small div and not fullscreen? [duplicate]

I have a link like this:
<a href="/index2.php?option=com_jumi&fileid=3&Itemid=11" onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,')
I want the new opening window to open in a specific size. How do I specify the height and width?
<a href="/index2.php?option=com_jumi&fileid=3&Itemid=11"
onclick="window.open(this.href,'targetWindow',
`toolbar=no,
location=no,
status=no,
menubar=no,
scrollbars=yes,
resizable=yes,
width=SomeSize,
height=SomeSize`);
return false;">Popup link</a>
Where width and height are pixels without units (width=400 not width=400px).
In most browsers it will not work if it is not written without line breaks, once the variables are setup have everything in one line:
Popup link
window.open ("http://www.javascript-coder.com",
"mywindow","menubar=1,resizable=1,width=350,height=250");
from
http://www.javascript-coder.com/window-popup/javascript-window-open.phtml
:]
window.open('http://somelocation.com','mywin','width=500,height=500');
Just add them to the parameter string.
window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=350,height=250')
<a style="cursor:pointer"
onclick=" window.open('http://YOUR.URL.TARGET','',' scrollbars=yes,menubar=no,width=500, resizable=yes,toolbar=no,location=no,status=no')">Your text</a>
These are the best practices from Mozilla Developer Network's window.open page :
<script type="text/javascript">
var windowObjectReference = null; // global variable
function openFFPromotionPopup() {
if(windowObjectReference == null || windowObjectReference.closed)
/* if the pointer to the window object in memory does not exist
or if such pointer exists but the window was closed */
{
windowObjectReference = window.open("http://www.spreadfirefox.com/",
"PromoteFirefoxWindowName", "resizable,scrollbars,status");
/* then create it. The new window will be created and
will be brought on top of any other window. */
}
else
{
windowObjectReference.focus();
/* else the window reference must exist and the window
is not closed; therefore, we can bring it back on top of any other
window with the focus() method. There would be no need to re-create
the window or to reload the referenced resource. */
};
}
</script>
<p><a
href="http://www.spreadfirefox.com/"
target="PromoteFirefoxWindowName"
onclick="openFFPromotionPopup(); return false;"
title="This link will create a new window or will re-use an already opened one"
>Promote Firefox adoption</a></p>
Using function in typescript
openWindow(){
//you may choose to deduct some value from current screen size
let height = window.screen.availHeight-100;
let width = window.screen.availWidth-150;
window.open("http://your_url",`width=${width},height=${height}`);
}
Anyone looking for a quick Vue file component, here you go:
// WindowUrl.vue
<template>
<a :href="url" :class="classes" #click="open">
<slot></slot>
</a>
</template>
<script>
export default {
props: {
url: String,
width: String,
height: String,
classes: String,
},
methods: {
open(e) {
// Prevent the link from opening on the parent page.
e.preventDefault();
window.open(
this.url,
'targetWindow',
`toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=${this.width},height=${this.height}`
);
}
}
}
</script>
Usage:
<window-url url="/print/shipping" class="btn btn-primary" height="250" width="250">
Print Shipping Label
</window-url>
Using a button to refer to another window with a single click
<Button onClick={() => {window.open("https://www.google.com")}}>
Button Description
</Button>

Window.open problems in html [duplicate]

This question already has answers here:
JavaScript open in a new window, not tab
(15 answers)
onclick open window and specific size
(9 answers)
Closed 3 years ago.
I am trying to open a new window with a button. The window needs to have a specific height and width. Whenever I click the "open" button it just opens a completely new tab.
var aWindow;
function openWindow() {
aWindow = window.open("", "", "width=400, height = 200");
}
function closeWindow() {
if (aWindow) {
aWindow.close();
}
}
<html>
<body>
<button onclick="openWindow();">Open</button>
<button onclick="closeWindow();">Close</button>
</body>
</html>
window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=300px,height=300px');
Try this code tested
Try to use this code
window.open('https://www.google.co.in/','_blank','toolbar=no, location=no, status=no, menubar=no, scrollbars=yes,resizable=yes, width=10px, height=20px')
DEMO LINK
<input type="button" value="Open a Popup Window" onclick="popupFunction('https://stackoverflow.com')">
<script>
// Popup window function
function popupFunction(url) {
popupWindow = window.open(url,'popUpWindow','height=500,width=500,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes');
}
</script>

Social Buttons do not share the current page info

I have been attempting to create social buttons that both capture the current page url automatically and the page description too.
i have gone through numerous questions & answers (found within stackoverflow) and followed the steps but I have come to some sort of problem with the social buttons behavior.
facebook: it pops up a new window and prompts me 'TO ENTER AN URL TO SHARE'. The new page's url is: https://www.facebook.com/sharer/sharer.php?u
twitter: simply asks me: 'WHATS HAPPENING?'. The popup url is: https://twitter.com/intent/tweet?text=&url=about%3Ablank&original_referer=
pinterest: in the description area, it just appends: #Url.Encode(PageTitle)
The popurl is: https://www.pinterest.com/pin/create/button/?url=%40Url.Encode(Request.Url.ToString())&description=%40Url.Encode(PageTitle)
In short, none of the buttons seem to be generating any page url nor descriptions and titles.
Here are my files:
index.html
<a class="soc-facebook popup" href="javascript:window.location=%22http://www.facebook.com/sharer.php?u=%22+encodeURIComponent(document.location)+%22&t=%22+encodeURIComponent(document.title)" title="Share on Facebook..." target="_blank"></a>
<a class="soc-twitter popup" href="javascript:window.location=%22https://twitter.com/share?url=%22+encodeURIComponent(document.location)+%22&text=%22+encodeURIComponent(document.title)" target="_blank"></a>
<a class="soc-pinterest popup" href="http://pinterest.com/pin/create/button/?url=#Url.Encode(Request.Url.ToString())&description=#Url.Encode(PageTitle)" target="_blank" title="Pin it"></a>
<a class="soc-google popup" href="https://plusone.google.com/_/+1/confirm?hl=en&url=<?php if(is_home()){echo home_url();}else{the_permalink();} ?>" target="_blank" title="Plus one this page on Google"></a>
<a class="soc-linkedin soc-icon-last popup" href="http://www.linkedin.com/shareArticle?mini=true&url=<?php if(is_home()){echo home_url();}else{the_permalink();} ?>" target="_blank"></a>
pop.js
$(function() {
// link selector and pop-up window size
var Config = {
Link: "a.popup",
Width: 500,
Height: 500
};
// add handler links
var slink = document.querySelectorAll(Config.Link);
for (var a = 0; a < slink.length; a++) {
slink[a].onclick = PopupHandler;
}
// create popup
function PopupHandler(e) {
e = (e ? e : window.event);
var t = (e.target ? e.target : e.srcElement);
// popup position
var
px = Math.floor(((screen.availWidth || 1024) - Config.Width) / 2),
py = Math.floor(((screen.availHeight || 700) - Config.Height) / 2);
// open popup
var popup = window.open(t.href, "popup",
"width="+Config.Width+",height="+Config.Height+
",left="+px+",top="+py+
",location=0,menubar=0,toolbar=0,status=0,scrollbars=1,resizable=1");
if (popup) {
popup.focus();
if (e.preventDefault) e.preventDefault();
e.returnValue = false;
}
return !!popup;
}
}());
where could i be possibly going wrong?
Thanks!
Here are the urls you should use
For twitter:
https://twitter.com/intent/tweet?text=MyTweetText&via=MyUser&url=http://google.com
For pinterest:
https://www.pinterest.com/pin/create/button/?description=desc&media=someUrlImage&url=http://google.com
You can use this page to create the urls: http://www.sharelinkgenerator.com/
The trick here is to add Open Graph metatags to the page that is being shared. These metatags are used by Facebook to capture page metadata. If you don't include metatags on the page then you can explicitly enter parameters for the Facebook sharer at least.
See this page for a synopsis on how to include these tags:
http://ogp.me/

How to prevent execCommand('SaveAs', from opening new tab or window

I have to generate a download pop up in IE.
Iam using the below code.
when i click on buttton it opens a new tab and the Save as Dialogue box
function SaveContents(element) {
if (document.execCommand) {
var oWin = window.open("about:blank","_blank");![enter image description here][1]
oWin.document.write(element);
oWin.document.close();
var success = oWin.document.execCommand('SaveAs', false, "FilteredReport.xls")
oWin.close();
}
}
How can i make the Save as Dialogue box appear with out opening new window or tab..
Also can i write data of a string to excel with out using
oWin.document.write(element);
beacuse its getting written to the new tab or window that opens
Below image explains..
Instead of IEwindow.document.execCommand('SaveAs', true, fileName + ".xls"); use below snippet
if (window.navigator.msSaveOrOpenBlob) {
blobObject = new Blob([CSV]);
window.navigator.msSaveOrOpenBlob(blobObject, 'Export.xls');
}
IEwindow.close();
include an iframe with ID IframeForExcelExportonIE
<iframe id="IframeForExcelExportonIE" style="display: none"></iframe>
IframeForExcelExportonIE.document.open("txt/html", "replace");
IframeForExcelExportonIE.document.write(cln.innerHTML);
IframeForExcelExportonIE.document.close();
IframeForExcelExportonIE.focus();
sa = IframeForExcelExportonIE.document.execCommand("SaveAs", true, " test.xls");

How to open new popup window from liferay portal using jsp?

How to open new popup window from portal using java script.
I have jsp page with button , if i click the button need to open new popup window from portal.
onClick="window.open('/html/viewpdf.jsp','mywindow','width=500,height=350,toolbar=no,resizable=yes')">
this doesn't working jsp page.
Try this:
onClick="
var organizationWindow = window.open('<portlet:renderURL windowState="<%= LiferayWindowState.POP_UP.toString() %>"><portlet:param name="jspPage" value="/html/viewpdf.jsp"/><portlet:param name="redirect" value="#"/></portlet:renderURL>',
'title',
'directories=no, height=340, location=no, menubar=no, resizable=yes,scrollbars=yes, status=no, toolbar=no, width=680');
organizationWindow.focus();"
you can create an icon <liferay-ui:icon image="add" message="Add a Person to this group" url="javascript:alertAdd();" />
then add the script that this icon calls to open the popup
<aui:script use="aui-dialog,aui-overlay-manager">
Liferay.provide(
window,
'alertAdd',
function() {
var instance = this;
var url='${details}';
Liferay.Util.openWindow(
{
cache: false,
dialog: {
align: Liferay.Util.Window.ALIGN_CENTER,
after: {
render: function(event) {
this.set('y', this.get('y') + 50);
}
},
width: 820
},
dialogIframe: {
id: 'addIFrame',
uri: url
},
title: Liferay.Language.get('cloud'),
uri: url
}
);
},
['liferay-util-window']
);
NOTE that you will need the URL ${details}
<portlet:renderURL var="details">
<portlet:param name="mvcPath" value="/html/grouping/member_search_popup.jsp"/></portlet:renderURL>
Yes , this opening popup window.But in liferay portal just opening http://localhost:8080/web/guest only. not opening the viewpdf.jsp.
my requirment is print the datatable values from the page.So datatable have scrollbar, though doesn't print page not correct.
So that i planned to display the datatable values in the popup window and there print button, it should display the all data.
function callsubmit(){
window.print();
window.opener.document.location = window.opener.document.location.href;
window.close();
}
I would like know how to print datatable all values to print.

Categories

Resources