Pop Under on Click for RSS Feed - Javascript - javascript

I want to set up the site so when users click on RSS feed links (which I display in part of the site), the feed link appears in a pop under. It makes sense on the site. It's something my users want.
What I can't figure out is how to populate the rss links that I'm pulling to get them to open in a pop under.
I've got this:
$(document).ready(function(){
$("a[href^='http']").attr('target','_blank');
});
which does open the link in a new window. I can add another line like this:
$("a[href^='http']").attr('onClick','openpopup()');
but I'm not sure how to craft some javascript that will 1) grab the href from the anchor; 2) replace it with a javascript(void); 3) use that url in something like this:
function openpopup() {
window.open("url","","toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,status=no,width=1250,height=500,left=250,top=175").blur(); window.focus();}
Any ideas?

Not much of a jQuery guy, but this should work
$("a[href^='http']").click(function(event) {
event.preventDefault(); // prevent the link from opening directly
// open a pop for the link's url
var popup = window.open( this.href , "", "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,status=no,width=1250,height=500,left=250,top=175" );
popup.blur();
window.focus();
});

Related

Open other webiste in new tab alogn with my website

I have a website-1 (www.example.com). When a customer reaches out to my website, the other website-2 (www.example2.com) should be open in a new tab corresponding with the website (www.example.com).
How to do this
I would like to add to Daan Teppema's answer.
Add rel property in the tag, if the website is not safe or untrusted add noopener. but if you are directing within your website remove the noreferrer for SEO tracking purposes.
Example 2
This will keep your website tab open and in the meantime open a new tab with the link you've provided.
You can do an <a> element with the target="_blank" attribute.
Like so:
Example 2
If you want them both to load, then you can make it go to the second one in another tab with javascript using the window.onload event.
Like so:
window.onload = function() {
window.open(url, '_blank').focus();
};

How to create a link without showing the url?

Could someone please share how to create a link and not letting the users know the url of the link?
For example in the following website, when you hover over the practice groups the mouse shows that its a hyperlink but the url doesn't get dsplayed.
verbling.com/community
I am developing a similar page. Kindly share how to create a link and not letting the users know the url of the link.
Following this simple example with jquery
Click Here
$(function(){
$('.do_action').click(function(e) {
e.preventDefault();
// Open link on same page
document.location.href = 'http://example.com';
// Open link in tab or other window
// window.open();
});
});
For new tab window.open()
you can add a click function and set the location throgh javascript like:-
$( document ).ready(function() {
$( "#target" ).click(function() {
location.href = 'http://address.com';
});
});
for this thing to work you have to include jquery, either from your server or from CDN like
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

Javascript: Clicking Link to Download pdf

I am working on a JS program which should open a webpage www.mysite.com & click on a link inside that webpage to download a pdf.
The link to click looks like this:
<a onclick="download();return false;" href="#noWhere">Click to Download</a>
Ordinarily, manually clicking the link, calls the following function to download the pdf:
function download() {
document.forms[0].action = path + "/xxW04_sv_0140Action.do";
document.forms[0].target = "_self";
document.forms[0].submit();
}
My code is simplified javascript code to open the page & click on the "Click to Download" button is this:
<script>
var linkname = "http://www.mysite.com";
var windowname = "window_1"
// Opens a new window
var myWindow = window.open(linkname, windowname ,"width=400,height=600");
//should open a link to download pdf
myWindow.document.getElementById('href = \"#noWhere\"').click();
</script>
So far I can open the webpage "mysite.com" in a seperate window using but for some reason no button clicking is happening and certainly no pdf is downloaded.
Of course if I manually click the "Click to Download" button it downloads.
Can anyone tell me what i'm doing wrong? Why I cannot simulate a click with the above js code?
Or possibly give me some things to try. Any help much appreciated and Than you.
UPDATE:
From the initial answers below, possibly this method is doomed for failure! Can anyone suggest a better way I could be downloading these pdfs?
You'd better use:
<a href="http://www.mysite.com/mypdf.pdf">
This should download that pdf file.
It won't work. The same-origin policy will prevent you from accessing the content of any pages loaded from another domain.
Also, as #kamilkp pointed out, you have to provide the getElementById() function with an id value. You can't just plug any old stuff in there and expect it to work.
Another problem is your reliance on clicks for this to work. What about users that use the tab key to select links and then press Enter to follow the link?

Disable Parent Window after open.window

I want to link to an amazon music preview player as an popup from my site. I have this code:
Link
My Problem is, when I click on the Album Cover in the Amazon Popup, my parent site with the link refreshs with the target Amazon url. When I open the Popup URL by typing the url in the adressbar and then click on the cover, a new window is opend with the target url (this is what I want to force).
Is it possible to don't pass the parent relation with the link popup window?
Make sure you are not using "popper" as the identifier for both instances of winow.open. The main one that opens the initial popup should be different from the one that is inside the popup itself, unless you want it to change the popup that is already open (in which case, the window.open in the onclick attribute is essentially unnecessary).
What I mean is by this:
Say you are launching the original popup with the code in question like this:
Popup
And the popup with the code in question is this (popup.html):
Link
You need to make sure the original popup identifier is different from the one in the popup. So, the original popup should be something like:
Popup
I solved my Problem using something like this:
Open a local popup.php from my site with JS while passing amazonurl as var.
<a onkeypress="window.open(this.href,'popup','scrollbars=1,width=900,height=600'); return false;" onclick="window.open(this.href,'popper','scrollbars=1,width=900,height=600'); return false;" rel="nofollow" target="_blank" href="http://domain.com/popup.php?amazonurl=http://[...]">Link</a>
In popup.php I use
<script language="javascript" type="text/javascript">
window.opener = null; window.location.href = "<?php echo $_GET['amazonurl']; ?>;</script>
To make windpw.opener = null and then refresh the popup with the amazon URL.

Using JQuery to open a popup window and print

A while back I created a lightbox plugin using jQuery that would load a url specified in a link into a lightbox. The code is really simple:
$('.readmore').each(function(i){
$(this).popup();
});
and the link would look like this:
<a class='readmore' href='view-details.php?Id=11'>TJ Kirchner</a>
The plugin could also accept arguments for width, height, a different url, and more data to pass through.
The problem I'm facing right now is printing the lightbox. I set it up so that the lightbox has a print button at the top of the box. That link would open up a new window and print that window. This is all being controlled by the lightbox plugin. Here's what that code looks like:
$('.printBtn').bind('click',function() {
var url = options.url + ( ( options.url.indexOf('?') < 0 && options.data != "" ) ? '?' : '&' ) + options.data;
var thePopup = window.open( url, "Member Listing", "menubar=0,location=0,height=700,width=700" );
thePopup.print();
});
The problem is the script doesn't seem to be waiting until the window loads. It wants to print the moment the window appears. As a result, if I click "cancel" to the print dialog box, it'll popup again and again until the window loads. The first time I tried printing I got a blank page. That might be because the window didn't finish load.
I need to find a way to alter the previous code block to wait until the window loads and then print. I feel like there should be an easy way to do this, but I haven't found it yet. Either that, or I need to find a better way to open a popup window and print from the lightbox script in the parent window, without alternating the webpage code in the popup window.
You should put the print function in your view-details.php file and call it once the file is loaded, by either using
<body onload="window.print()">
or
$(document).ready(function () {
window.print();
});
Got it! I found an idea here
http://www.mail-archive.com/discuss#jquery.com/msg18410.html
In this example, they loaded a blank popup window into an object, cloned the contents of the element to be displayed, and appended it to the body of the object. Since I already knew what the contents of view-details (or any page I load in the lightbox), I just had to clone that content instead and load it into an object. Then, I just needed to print that object. The final outcome looks like this:
$('.printBtn').bind('click',function() {
var thePopup = window.open( '', "Customer Listing", "menubar=0,location=0,height=700,width=700" );
$('#popup-content').clone().appendTo( thePopup.document.body );
thePopup.print();
});
I had one small drawback in that the style sheet I was using in view-details.php was using a relative link. I had to change it to an absolute link. The reason being that the window didn't have a URL associated with it, so it had no relative position to draw on.
Works in Firefox. I need to test it in some other major browsers too.
I don't know how well this solution works when you're dealing with images, videos, or other process intensive solutions. Although, it works pretty well in my case, since I'm just loading tables and text values.
Thanks for the input! You gave me some ideas of how to get around this.
Are you sure you can't alter the HTML in the popup window?
If you can, add a <script> tag at the end of the popup's HTML, and call window.print() inside it. Then it won't be called until the HTML has loaded.

Categories