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.
Related
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();
};
So I am using php to list out some users from the database and have put a <a href="" link with them.. The issue is, I want to be able to open the new file on a new tab but if i use target="_blank" everytime i click on that link a new tab will open. I don't want that. Once a new tab has been created, if i click on it again, it should take me to the tab thats already open.
Yes, I have looked this up on stackoverflow and i did come across this solution:
<script type="text/javascript">
var myWindow = null;
$('.title').on('click', function(){
if(myWindow == null || myWindow.closed)
myWindow = window.open('i.php', 'myWindow')
else
myWindow.focus()
});
</script>
So I understand how to use this for an html page or when you have to directly go to a page but I am making use of php and ?id=to go to a different page.. Not just that, my a link in php has been set inside a while loop so that all users could be displayed from the list.
while($msg=mysqli_fetch_assoc($msgs))
{
$s=mysqli_query($conn,"SELECT * FROM `users` WHERE `Email`='".$msg['Email']."'");
while($ms=mysqli_fetch_assoc($s))
{
echo '<div class="w3-col m3"><a href="chatbox.php?toUser='.$msg['Email'].'" target="_blank" rel="noopener noreferrer">
<img src="black.png"></a><br>
<label for="name">'.$ms['FullName'].'</label><br>';
}
}
so as you can see.. here I need to find a way to click on the <a link and for a new tab to open just once and then if i click on the same thing again, it should just take me back to the same tab.. But I am not able to figure out how to do this
If you specify target="_blank" then it will open up in a new tab. If you specify target="..." with a unique name, then it will try and reference a window with that name.
You need to construct some kind of unique name per tab.
If you're using window.open() you've got to keep track of any previously opened windows, so I'd suggest some kind of object where the key is the tab and the value is the window created.
It's worth noting that window.open() is really user hostile, it's considered a "pop up" by some blockers, and you should let target do the work for you.
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?
Trying to open a link in a framed page and close the child window. The link bellow is in a child window and when I click it opens the link in the framed page, but did not close the child window
<a target="Resultado" href="?Tela=1"
onClick="javascript:return confirm('TryMe');window.close();">
I have used a code like this to close the window... but couldn't get it to work with the above code.
<a href="javascript:window.opener='Resultado';window.close();">
Try this:
<a target="Resultado" href="?Tela=1" onclick="clickHandler(event, this);">Link</a>
And declare this:
function clickHandler(e, el) {
var choice = confirm('TryMe');
if (!choice) {
e.preventDefault();
}
window.close();
}
I wasn't sure of your original use of window.close() since it came after the return and would never execute, so it's up to you to move it to where you want.
Create another webpage on your webserver & use that as the Custom URL thankyou page for your form.
In that new webpage have just one line of code.
<body onload="javascript:window.opener.childClosed();window.close();">
--
That code will call a javascript function in the parent window and then close the child popup; you can then use that javascript function to do a redirect on your parent page.
I am not to sure where the URL of your 'Thank you for requesting...' page is, but here is some javascript to redirect to google on your parent page after the form is submitted.
function childClosed() {
window.location = "http://www.google.com/"
}
You can put that script before your closing <body> tag.
--
Hopefully I have understood your query OK, let me know if you have any questions or need any clarification on this possible solution.
-
I have made a very basic clone of your webpage & form here if you want to test out the functionality, 'Factoring Question?' is the link that contains this code.
I used Tinybox
http://sandbox.scriptiny.com/tinybox2/
to open a popup web page.
I hope when I click the links on the web page, the popup web page will close and automatically redirect to the link url I click
my javascript codes and html codes
<script type="text/javascript" src="tinybox.js"></script>
<script type="text/javascript">
function openJS(){}
function closeJS(){}
function closeAndGotoURL{
TINY.box.hide();
opener.location.href='http://www.google.com';
}
Open page2
//...below is on webpage2.html, it does not work
Click
but this looks like not to work
Instead of opener.location.href, use parent.location.href. See below:
function closeAndGotoURL {
TINY.box.hide();
parent.location.href='http://www.google.com';
}
You could also use top.location.href:
function closeAndGotoURL {
TINY.box.hide();
top.location.href='http://www.google.com';
}
Another option would be to use pure HTML. Although it wouldn't close the pop up first, it would redirect the entire window to your URL. Notice the target attribute of the anchor tag.
<a href="http://www.google.com" target="_top">
NOTE 1: Why close the pop up first? If you're redirecting the whole page, just redirect - no need to close the pop up.
NOTE 2: This will only work properly if the page that is loaded in the iframe is on the same domain as the parent window (I'm assuming that it is since you're writing the pop up code).