I have an interactive map that is set in an iframe in a word press web page. the links are passed to a javascript function. when I click on a link on the map I want it to go to another web page altogether, but it keeps loading that web page into the iframe no matter what I try.
I tried 3 different ways of linking to it in the javascript.
function go2Link(e,link) {
var code = (e.code ? e.keyCode : e.which);
if (code == 13) {
//window.parent.location.href = link;
//window.open(link)
window.parent.open(link);
}
}
But instead of it going to a new web page, the web page does not seem to break out of the iframe and gets downsized inside it.
Have you tried window.parent().open(link); ?
And otherwise I think you can try window.parent().parent().open(link); if that doesn't work.
window.parent.open(link, '_blank');
This will open that link in another tab itself.
Cheers
I figured out the problem. that particular link was missig the target="_parent" tag the others had in the normal a href tag. it wasn't in the javascript link at all. that was working fine. dummy me.
Related
I want to do that when I clicked on link (for example test.com/page?=test) my tab in the broswer open the link but without reload or refresh the page and change the content to the page content.
How can I start it? I know PHP, but its the first time that I try to do this.
Well, i doubt there is any easy way for this.
https://www.w3schools.com/xml/ajax_intro.asp
This might help.
You can use HTML5 History API
document.body.addEventListener('click', function(event){
if(event.target.tagName === 'A'){
event.preventDefault();
history.replaceState({}, "Page Title", event.target.href);
}
})
I want to open 2 URLs on click.
This can be done through jquery, javascript whatever I don't care.
I prefer lightweight and speed but at this point anything is fine with me.
I tried including onclick in the a href and also open.window in jquery.
Both gave me a: "popup blocked"
What is the correct way to do this?
HTML
Click Here
JS:
$('a.yourlink').click(function(e) {
e.preventDefault();
window.open('http://yoururl1.com');
window.open('http://yoururl2.com');
});
Otherwise do it in simple way
multiopen
Setup a link with target="_blank" to ensure the popup opens as _blank is okay with all browsers.
Then after it is opened, substitute current address with javascript's window.location;
2 links
<script>
$('a.bob').on('click', function(e){
window.location.href="http://yahoo.com"
});
</script>
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?
I currently have a form set up with 5 radio options. I have a switch statement depending on the option you pick and that determines where the email is going to go.
Inside my switch, I have this piece of code.
window.open("mailto:"+emailTo+'?cc='+emailCC+'&subject='+emailSub+'&body='+emailBody);
It all works fine when it opens up my email client with all of the content however it also opens a blank page in the browser.
Is there another way to achieve this or prevent a blank window from opening but still make it as if you clicked on the href:mailto ?
Instead of:
window.open("mailto:"+emailTo+'?cc='+emailCC+'&subject='+emailSub+'&body='+emailBody);
You can try:
location.href = "mailto:"+emailTo+'?cc='+emailCC+'&subject='+emailSub+'&body='+emailBody;
The second argument in window.open is the target.
window.open('mailto:'+emailTo+'?cc='+emailCC+'&subject='+emailSub+'&body='+emailBody, '_self'); should do the trick.
Location.href doesn't seem to work in chrome.
I do it like this:
x=window.open("mailstring");
x.close();
Works perfect for me.
After your "window.open" statement, try running an "if statement" to check and see if a new window was opened so that it will close.
if (win && win.open && !win.closed)
{
win.close();
}
This will happen very fast so the users might notice that a window opened and closed before the email application opened.
Howdy guys, im having trouble finding help on creating a callback in certain situations.
I have a piece of code which loads a links page in to an iframe and then changes the scr if another link is pressed.
$(".iframe").hide();
$(".lnk").click(function(){
$(".iframe").show('slow')
;})
;
$(".frmclose").click(function(){
$(".iframe").hide('slow')
;})
;
The above runs within (document).ready
below is outside of this (for some reason it does not work on the inside)
function changeIframeSrc(id, url) {
if (!document.getElementById) return;
var el = document.getElementById(id);
if (el && el.src) {el.src = url;return false;}return true;}
the link :
google
prior to this i have the div in which the iframe is in become unhidden. I also have a button within that div which hides the div + iframe.
What im having problems with is once the iframe has been opened and then closed via the div link if it is re-opened by clicking a different link the iframe unhides to display the old page then changes. But what i want is for the frame to load the new page(while hidden) then unhide to display it. I thought of using a callback after the iframe src change but i cant see where i would implement it.
Example of it happening
(click the GDPH button to see the links for the iframe)
Any thoughts or help appreciated.
Regards
B Stoner
I think that all you need to do is clear the src of the <iframe> when it is closed. That will clear the page so that next time you show the iFrame it will start out blank again.
I made a small demo of this functionality that uses the 3 links from your page as an example. The <iframe> starts hidden (by CSS) and each link will show the <iframe> and then load the remote site. I added a close iframe link to simulate the close link you have under the <iframe> on your site.
Hope this helps!
Edit: Updated the demo link to include the callback part. Somehow missed that when I read the question!
Edit 2: Your changeIframeSrc function was not working was because it was defined inside the jQuery anonymous function and is a closure. See calling Jquery function from javascript
I would catch the .load() event for the iframe, this will fire after the document has been loaded in to the iframe.
$(".iframe").load(function { /* code to run when iframe is loaded */ });