How to open results in another page - javascript

This is probably a simple question but I cannot figure out how to open the results from my database in a javascript popup window. I have an index.php page with a input box and an input button. When the user selects a date and presses the button, I'd like the results to open in a new window. How can I do this?
Thanks

I strongly suggest not doing this — http://diveintoaccessibility.org/day_16_not_opening_new_windows.html — but if you insist, then:
<form action="…" target="_blank">

This can be done with simple html:
Link Text

You need to open your new window using window.open. What you could do, is pass the date in as a querystring parameter to the URL that makes up the popup window page, and then use that parameter to perform the lookup from the database.
This page shows how to use window.open.

Use window.open to open another window. And than use this window to document.body.innerHTML your data.example
var wnd=window.open('','newWnd');
wnd.document.body.innerHTML="test"

Related

How to use window.location.replace in jquery or javascript

I have a website for which I have implemented livechat, when user clicks on livechat link it opens a new window that is fine. I want to do is when no operator is online then it should not open a new window when livechat link clicked instead it should redirect to the contact us page of the website in the same window in the currently opened tab, Is it possible?
I do not know how is it possible, what I have tried is this , it redirects to this page but opens in a new window.
window.location.replace('http://mywebsite.com/index.php?route=information/contact');
The problem is somewhere in the code around that. You need to call that code in the old window.
If you want to call it in the chat window, try:
window.opener.location.replace('http://mywebsite.com/index.php?route=information/contact');
window.close()
Use the href property instead:
window.location.href = 'http://mywebsite.com/index.php?route=information/contact';
You can use simple javascript code like this: window.location.href = "SOME URL"
it will do the same think. .

How to open link in new Tab by pressing Button? in jade

The following
button(type="button", target="_blank", onclick="location.href='auth/google';")
does not work. It opens link in the same window. Just for reference, its part of node.js program, in which i'm using passportjs for google authentication.
The button isn't actually opening a link - it's just running some javascript code that happens to, in this instance, be navigating to a new URL. So the target="_blank" attribute on the button won't help.
Instead, you need to use javascript commands to open a new tab/window, rather than using javascript to change the URL of the current window. Assigning to location.href will only change the URL of the current window.
Use the window.open(url, target) function instead - it takes a URL, and a target window name, which behaves the same as the target="whatever" attribute on a link.
window.open('auth/google', '_blank');
Your complete code would look like this:
button(type="button", onclick="window.open('auth/google', '_blank');")

open multiple webpages in same tab

Have multiple hyperlinks in a report, everytime a click on a hyperlink the webpage opens in a new tab,
Is it possible to open the hyperlinks in only one tab instead of multiple tabs using javascript ?
Please help
I am currently using window.open to open the webpages, I cannot use target. Below is the code :
I basically have a jqgrid where all the values of a column have hyperlink,
if (GridColNum == 2) //index of the column
{
localStorage.valuekey = $('#filters_grid').jqGrid('getCell', GridRowId, 1);
window.open('http://mywebpage.html');
}
And i am using the clicked value in another page using localstorage feature
Yes, it's possible. Use syntax
<a href="..." target="rptTab"/>
for all relevant links. This way the first time a link is clicked a new tab will be opened; for subsequent clicks, that tab will be reused.
EDIT: if you're opening the link in javascript using window.open, then you need to specify the name of the tab/window as the second parameter:
window.open('http://mywebpage.html', 'rptTab');
You probably have a target='_blank' attribute in your links. Just remove them. If that does not help please post some code so we can see what is happening
When you specify the target of a window.open() call or an tag, you can specify _blank, _parent, _self or _top, as special tab/window names. Alternatively you can specify a new tab/window name, when you specify this tab/window another time, it will refer to the original one that you opened.
hyperlinks opens a new browser tab - is due to
target='_blank'
attribute of it. you can remove it using following jQuery code.
$('a').removeAttr('target');
now on-wards every link will get open in the same page.
You don't need javascript for this. Just use the target-attribute of the a tag. All links with the same target should be opened in the same tab.
http://www.w3schools.com/tags/att_a_target.asp

How to put a window opened with window.open() behind the opener window?

I have a link that when clicked replaces the current page with another through the default <a> element click behaviour, but which also calls a JavaScript function to open another page in a new window. I would like the new window opened from my JavaScript function to appear behind the current window but can't figure out how to do this. In actual usage, I am feeding click thrus to a database, the link that is controlled by the window.open statement. The other link is to the clients site in a new window. I want the clients site to appear on top.
My current code is as follows:
<script language="JavaScript" type="text/JavaScript">
function countClicks(a,b)
{
window.open("http://stackoverflow.com?id="+a+"&id2="+b, "_blank");
}
</script>
test
So for the example URLs shown above I would like the (original) window with Google to appear in front of the new window with StackOverflow, but the new window always opens in front.
Try using window.focus() at the end of your existing function:
function countClicks(a,b) {
window.open("http://stackoverflow.com?id="+a+"&id2="+b, "_blank");
window.focus();
}
That should bring the existing window back to the front, noting that behaviour may vary between browsers and depending on popup-blocking settings, etc.
Or you could just swap the two urls, i.e., put the StackOverflow url in the href with the appropriate query string specified directly rather than in JS, and put the Google url in the window.open() call.
Popup behavior varies based on browser/user settings. I haven't been able to replicate the open behind behaviour myself, but I believe what you're looking for is .focus().
Try:
window.open("http://stackoverflow.com?id="+a+"&id2="+b, "_blank").focus();

What's the simplest way to get an image to print in a new window when clicked?

I'm trying to create a simple click to print link for an image, and what I'd like to happen is when the link is clicked, a new window opens with the image, and the browser opens the print command dialogue box.
My question is whether this is possible just from a URL parameter, or from the anchor element on the initiating page? Or do I have to build a target page with javascript to do this?
Here's a sample of what I've got:
<p class="click-2-print">
Click here to print the map above
</p>
Obviously the code above will open the image in a new window, but still requires to user to hit Ctrl+P, Cmd+P or use the browser commands. My client wants the image to "just print" when the user clicks the link, so I'm trying to find the simplest way to accomplish this.
So is there any parameters or attributes that I can add to the above markup to accomplish what I have described?
You'll have to call window.print(). Perhaps something like this?
function printimage(){
var URL = "http://myimage.jpg";
var W = window.open(URL);
W.window.print();
}
Another option may be to put the image on a page that tells the browser to print when loaded. For example...
<body onload="window.print();">
<img src="/img/map.jpg">
</body>
Cody Bonney's answer will not work in certain browsers if the full url includes the image extension. The browser will automatically download it as soon as the new tab opens. You can get around this like so.
var url = scope.src;
var w = window.open('', '');
w.document.write('<html><head>');
w.document.write('</head><body >');
w.document.write('<img id="print-image-element" src="'+url+'"/>');
w.document.write('<script>var img = document.getElementById("print-image-element"); img.addEventListener("load",function(){ window.focus(); window.print(); window.document.close(); window.close(); }); </script>');
w.document.write('</body></html>');
w.window.print();
This will open a new page with the image, prompt the user to print, and after printing, close the new tab and reset focus to the original tab.
Disregard the scope.src that is angular specific code. Everything else should work as long as you provide your own url value from somewhere else
I would recommend you create a page in whatever language or framework you are working in that accepts a querystring argument for the image path, output that image in the document and have an onload / ready call to window.print(). Link to that instead of the image directly, and keep the target="_blank" and you should be set.
You have to call window.print() in javascript to trigger the browser print dialog. I'm pretty sure you can't trigger a print without user interaction unless you run a signed applet.
Hey Jag. Although its not exactly what you are looking to do, I did write this tutorial while I was working at a web design firm. You can probably rummage that code to get the link that prints the image. Basically what this code does it add a print button to the fancybox jquery plugin. I dont see why you couldnt just use the print part to add it to whatever you need. Hope it helps.
Add print ability to fancybox jquery plugin

Categories