I'm working with php to make some web pages and I'm having a bit of struggle with a link I'm trying to make.
Basically I have my <a> set with target="_self" on it so that it stays on the same page. (Note the page is a new window and that I also tried using "_top" and "_parent")
<img src="<?php echo $donnees[0]['id2_pathImgMini'] ?>" width="75" height="75" />
This is said link in its php form.
<img src="../images/propriete/DosAssorti/mini/L482_mini.jpg" width="75" height="75" />
This is the result arcoding to the browser when showing the source code.(Across IE,Firefox,Chrome)
<a target="_blank" href="http://ordi-003/inclusion/fiche.dos.assorti.info.php?id=14&lan=fr">
This is the same line according to Firebug AND the Chrome developping tools.
When clicking the linking the expected result is opening the link on the same page, however it opens it in a new window. Changing inside firebug "_blank" to "_self" and clicking the link afterwards gives the good results and opens the link on the same page.
Am I doing something wrong? Am I incorrectly using the <a> here?
Should I look for another way to make my link? I'm pretty open to anything really I tried different things and looked alot on google but couldn't find people with the same problem. Firefox cache is deactivated so that should not be the issue. Tried it on another computer too and it gives the same results.
If I gave too short information just tell me what I should also include as I am new to stack overflow.
Edit:I forgot to say that if I remove the target parameter and just put none, the "source code page" doesn't show anything like it should but in firefug and chrome dev tools it shows a target="_blank" still. Also just a note, there is only 1 copy of this file and it is on the localhost of the machine running the local site. I'm directly editing that file.
Edit2: http://pastebin.com/yrAMQEL9 be aware the indentation is awful on pastebin for some reason.
You're running different code than the code you're editing. Make sure your changes are making it to the server you're visiting in the browser and that you're editing the right file.
I finally found what was causing the replacement of my _self.
In the footer there was a script which was referenced and trough further research I found this bit of code
jQuery('a[href^=http]:not(.in)').attr({
'target' : '_blank'
});
It caused the replacement of the _self to a _blank.
Now that I know where the problem came from I just have to check with the original coder of that function why he needed it and if it is still needed.
Thanks all for your help.
Related
I have an application form I need to work into an iframe, but I'm having a hard time with the links for it. Because the iframe was initially giving me errors, I started a work around by having a workaround.php file made that would be read as:
<!DOCTYPE html><html><?php echo file_get_contents($_REQUEST['url']); ?></html>`
Then in the iframe on my page I wrote:
<style><!--iframe.Application {
overflow: hidden;
}
--></style>
<iframe width="100%" height="800px" style="height: 100vh;" class="Application" scrolling="no" src="https://www.mywebsite/workaround.php?url=https://theotherwebsite.com"></iframe>
This worked out very well and I now had the form loading seamlessly onto my website. The next issue was that the links are not working. Any root-relative link within the iframe form was linking to "https://mywebsite.com/page2" rather than to "https://theotherwebsite.com/page2".
Now the manager of the website with the form would be able to change these relative links to absolute links, so this isn't a huge obstacle. To test if it would work, I edited the links in my browser to be an absolute to:
<a href="https://theotherwebsite.com/page2">
For this the iframe refused to connect. I'll need to continue to use workaround.php. Next I tried:
<a href="https://www.mywebsite/workaround.php?url=https://theotherwebsite.com/page2">
For a moment, I see the 2nd page load within the iframe, but then the page opens outside of the iframe in the same tab & window. Additionally, the page that loads is "https://www.mywebsite/workaround.php?url=https://theotherwebsite.com/page2"
At this point, I'm unsure of what link would function and stay within the iframe. I tried to add the "_parent" target.
<a href="https://www.mywebsite/workaround.php?url=https://theotherwebsite.com/page2" target="_parent">
but this changed nothing from my previous attempt. I tried likewise with _self and _top to find no change. _blank still functioned to open the page in a second tab.
At this point I'm not familiar enough with iframes to know what else to attempt. I hope my explanation of past attempts and results is easily understood. If any of you have a suggestion of what could be a solution please let me know!
TLDR: How do I open a link within an iframe of a php document without it opening a new tab?
Community,
I would like to run a script when you click a link, but this shouldn't open in a new frame, that's why I added the following:
<iframe style="display:none;" name="target"></iframe>
<a href="script.php" target="target">
The script now executes without popping a blank page, joy. But I want the same link to open a PDF file.
<a href="pdf/cesar.pdf" target="_blank" > click here to download </a>
But now the PDF doesn't show, as the target frame is hidden. I can't seem to combine these two. Can someone help me out on this?
Cheers!
Cesar.
It sounds like you might be over-engineering this. Consider the high-level requirements:
The link needs to:
Execute PHP code
Open a PDF file
This sounds like two actions, but from the perspective of the client it's really only one action... open the PDF file. The rest is up to server-side code.
So create one link to perform that one action:
click here to download
As long as getPDF.php returns a PDF file, the client will never know the difference. What that PHP code does before returning that file is up to you. You can have all the code you want in that file, as long as the resulting response is returning the PDF file back to the client.
With the display none it will never show up, you probably should use jQuery, I'd added an ID to the "a"
<iframe style="display:none;" name="target"></iframe>
<a href="script.php" id="openPdf" target="target">
and when click:
$(document).on("click","#openPDF",function(){
$("iframe").css("display","block");
});
This is probably a very easy question however I have been banging my head for the last week on how to solve this problem
I am using query tabs
In say tab 6 I have got a link to a php file. What I want to do is when tab 6 is opened display the url e.g. my folder/file.php?p=x&p=y&p=z .inside the tab.
I have tried the following:
<img scr="folder/file.php?p=x&p=y&p=z">
also
However noting will display
Is there anybody who can help?
thanks for looking
<img scr="folder/file.php?p=x&p=y&p=z">
Should be
<img src="folder/file.php?p=x&p=y&p=z" />
notice the typo in scr/src ^
I'm trying to determine which of the following (the fallback or the src link) actually gets rendered to the screen:
<img fallback="http://link1.gif" src="http://link2.gif">
I need a way of figuring out which of the images I would actually see on my screen (using PHP).
Note: This is the first time I've seen the fallback attribute and this is part of someone else's code (I've replaced the actual links for security reasons).
Rahter then using fallback you should use onerror.
<img src="http://link1.gif"
onerror='this.onerror = null; this.src="http://link2.gif"' />
This works also great crossbrowser.
Hope it helps.
Update the onerror to
http://domain.com/track.php=failed_image_on_screen=link1.gif
The browser then should make a http request to the php script so you can catch and log
I've got an ahref that when clicked, changes the content of 3 iFrames. Here's the code:
<a href='weekone.php' target='weekone' onclick='window.open("weektwo.php","weektwo"); window.open("weekthree.php","weekthree")'>Link</a>
Now this works perfectly in Firefox, Safari etc but doesn't work in IE. Can anyone shed some light on this problem for me please? I can't use a Javascript because I'm working within a PHP framework and the iFrame links are called from the database.
UPDATE
It appears the issue lies with spaces in the URLs called from window.open! As I'm calling info from a database (ie - "weektwo.php?Name=Bob and Dave") how can I get around this??
What version of IE?
Tested on IE 8 and this worked perfectly.
<a href='test.htm' target='weekone' onclick='window.open("test.htm","weektwo"); window.open("test.htm","weekthree")'>Link</a>
<iframe name='weekone' id='weekone' width=100 height=100></iframe>
<iframe name='weektwo' id='weektwo' width=100 height=100></iframe>
<iframe name='weekthree' id='weekthree' width=100 height=100></iframe>
If you're trying to open links in an <iframe>, it's probably easier to do
document.querySelector('iframe[name="weekone"]').src='test.htm';
document.querySelector('iframe[name="weektwo"]').src='test.htm';
document.querySelector('iframe[name="weekthree"]').src='test.htm';
(I've used document.querySelector because it's the easiest, but of course you can use document.getElementById or whatever way you want to get a reference to the <iframe>.)
On the back of the comments, try adding "return true;" to the end of the onclick (untested)...
<a href='weekone.php' target='weekone' onclick='window.open("weektwo.php","weektwo"); window.open("weekthree.php","weekthree"); return true;'>Link</a>
UPDATE
In light of the updated question, try "HTML Encoding" the query strings using the PHP function "htmlentities".
I'm basing the following on your original (pre-edited) code. So in this case I apologise for asking you to edit it, but I did ask you to show exactly what was being sent to the browser...
<a href='weekone.php?Name=<?=htmlentities($i[Name])?>' target='<?=$i[Name]?> weekone' onclick='window.open("weektwo.php?Name=<?=htmlentities($i[Name])?>","<?=$i[Name]?> weektwo"); window.open("weekthree.php?Name=<?=htmlentities($i[Name])?>","<?=$i[Name]?> weekthree")'>Link</a>
UPDATE 2 (due to me being stupid)
It shouldn't be "HTML Encoding" it should be "URL Encoding" using "urlencode"...
<a href='weekone.php?Name=<?=urlencode($i[Name])?>' target='<?=$i[Name]?> weekone' onclick='window.open("weektwo.php?Name=<?=urlencode($i[Name])?>","<?=$i[Name]?> weektwo"); window.open("weekthree.php?Name=<?=urlencode($i[Name])?>","<?=$i[Name]?> weekthree")'>Link</a>