Log in

View Full Version : pdf within an iframe



Glett
11-09-2015, 05:46 AM
hello what I am trying to do , is that I have 2 web pages, the first we will call first.html , and the second, second.html.

What I want to happen is this , when I click on a certain link , on first.html, I want for second.html , to appear , and also on an iframe , in second.html, I want a pdf to show up.

Beverleyh
11-09-2015, 06:08 AM
It isn't clear what you're trying to achieve. If you show us what you have tried, we can offer suggestions, but unfortunately, we can't troubleshoot something we can't see.

It sounds like you should do some research into iframes and the target attribute too, so start there and post back when you have a basic demo prepared for us to look at.

styxlawyer
11-09-2015, 10:00 AM
This sounds like a homework exercise and we won't do your homework for you as you would learn nothing from it.

As Beverley says, you need to do some research. Try starting here (http://www.htmlcodetutorial.com/frames/_IFRAME.html) and then here (https://www.google.co.uk/search?q=href+target+iframe).

Glett
11-09-2015, 03:39 PM
I have done my homework, a whole lot of searching, and cannot find the answer , Go to http://wayfarer.atwebpages.com/first.html and it willl explain things further.

Beverleyh
11-09-2015, 03:49 PM
Unfortunately, I cannot access your website because it is being flagged as malware by the filters on my network. Hopefully someone else can help

Glett
11-09-2015, 04:48 PM
I do not know why it is considered malware , does the index page show up as malware also??? Anyhow here are pictures or screenshots of the pages.57305731

styxlawyer
11-09-2015, 04:52 PM
Well, you clearly haven't done much research as the first hit on Google for "iframe" led to this page (http://www.w3schools.com/tags/tag_iframe.asp).

Your page is probably flagged as malware because of the content of the active link which is a JavaScript redirect. If you want to create a link for general use just use the <a>...</a> tags and not Javascript which could hide all sorts of devious stuff (and in your case actually does!).

Glett
11-09-2015, 05:44 PM
I looked at the web page you showed me , and I already knew this stuff, it is not at all what I am trying to do, and there is no devious stuff on my web page, it is a study of the trinity I wrote.

Glett
11-09-2015, 05:54 PM
Now my index page , on that website , I use to have a study on Scribd , but took it off of Scribd , that would be why the study of the index page does not function.
I could try the <a></a> tag , but in the end it is much more than that , that I am trying to do , instead of writting a seperate page for each study, I wnat all of my studies to show up in this one iframe , on the second web page , I have succeeded in doing this on my studies page, but not on my index page, my iframe is on the studies page.

Hope you can help , just want answers , not asumptions.

Glett
11-09-2015, 06:20 PM
Here is a code I used.



<div onClick='document.getElementById("someID").src="https://onedrive.live.com/embed?cid=0912027297A21B07&resid=912027297A21B07%218989&authkey=AD_ol5nd3vdkIvY&em=2&wdStartOn=1&wdEmbedCode=0&wdPrint=0";'>PDF test 1</div> <br><bR>


<iframe id='someID' frameborder="1" scrolling="no" width="100%" height="355"></iframe>

But now I changed it to an <a> tag.


<a onClick='document.getElementById("someID").src="https://onedrive.live.com/embed?cid=0912027297A21B07&resid=912027297A21B07%218989&authkey=AD_ol5nd3vdkIvY&em=2&wdStartOn=1&wdEmbedCode=0&wdPrint=0";'>PDF test 1</a> <br><bR>


<iframe id='someID' frameborder="1" scrolling="no" width="100%" height="355"></iframe>

this works on my studies page, but what I want is when I click on a link on my index page, that it brings me to my studies page, and also open my study in the iframe that is on the studies page.

I tried alot of codes including the web page you sent me too, but thanks for letting me know about stuff on the <a> tag and javascript.

styxlawyer
11-09-2015, 11:01 PM
The w3schools.com "iframe" page has this line right at the start:



<iframe src="http://www.w3schools.com"></iframe>


Now what you need to do is go back to that page, scroll down to the list describing the various attributes that an iframe can have and read about the purpose of the "src" attribute.

Glett
11-10-2015, 04:40 AM
I hope people understand what I am saying , I have a drop down menu on my site, and each link will linkto a different study, and i want each study, one at a time to show up in the iframe, I am trying to eliminate as much web pages possible on my website, actually I just want to web pages.

Thanks in advance.

styxlawyer
11-10-2015, 10:15 AM
I hope people understand what I am saying , I have a drop down menu on my site, and each link will linkto a different study, and i want each study, one at a time to show up in the iframe, I am trying to eliminate as much web pages possible on my website, actually I just want to web pages.

Thanks in advance.

Now you have explained what you are trying to achieve a little more clearly, I think you would get better results using PHP. Serve the second page with the appropriate content by a call from the first page passing a parameter to the second. All the hard work is then done on the server.

Beverleyh
11-10-2015, 11:20 AM
I hope people understand what I am saying , I have a drop down menu on my site, and each link will linkto a different study, and i want each study, one at a time to show up in the iframe, I am trying to eliminate as much web pages possible on my website, actually I just want to web pages.

Thanks in advance.

OK, I think I understand what you're trying to do now. I would opt for PHP - if you can use PHP you can do something like this.

For the links (on any page);


<a href="page.php?s=study1">Page 1</a>
<a href="page.php?s=study2">Page 2</a>
<a href="page.php?s=study3">Page 3</a>


And in the 'page.php' page with the iframe, put this right at the top - even before the doctype (very simple - untested);


<?php

if ( (isset($_GET['s'])) && ($_GET['s'] == 'study1') ) { $src = 'path/to/study-01.pdf'; }

if ( (isset($_GET['s'])) && ($_GET['s'] == 'study2') ) { $src = 'path/to/study-02.pdf'; }

if ( (isset($_GET['s'])) && ($_GET['s'] == 'study3') ) { $src = 'path/to/study-03.pdf'; }

?>


And then further down in your HTML you echo the $src variable into your iframe src attribute;

<iframe src="<?php echo $src ;?>"></iframe>

Glett
11-10-2015, 06:25 PM
Ok it seems to want to work but what it dispalys in the iframe is page not found. I called my page studies.php , and in the links I put:


<a href="mystudies.php?s=study1">Page 1</a>
<a href="mystudies.php?s=study2">Page 2</a>
<a href="mystudies.php?s=study3">Page 3</a>

and in the php quote (which my program already put the <?php ?> tags) I put:


<?php
if ( (isset($_GET['s'])) && ($_GET['s'] == 'study1') ) { $src = 'https://onedrive.live.com/embed?cid=0912027297A21B07&resid=912027297A21B07%218989&authkey=AD_ol5nd3vdkIvY&em=2&wdStartOn=1&wdEmbedCode=0&wdPrint=0'; }

if ( (isset($_GET['s'])) && ($_GET['s'] == 'study2') ) { $src = 'C:\Users\ASUS\Documents\My Websites\HisCross\Hiscrosstester\Grace.pdf'; }

if ( (isset($_GET['s'])) && ($_GET['s'] == 'study3') ) { $src = 'Grace.pdf'; }
?>

and for the iframe which appears with the links, I put:



<iframe src="<?php echo $src ;?>"></iframe>

But when I click the links , the pdf files do not show up , even though they are the right file path.

I think we are going in the right direction with this php code just need to get the pdf's tp show, thanks a whole lot.

Glett
11-10-2015, 06:35 PM
The pdf's did not show up on the desktop side of things but when I uploaded it to my test website server , it worked just great , does php only function on the server side? and not on the client side (hope I am saying this stuff right)? Anyhow thanks alot Beverleyh and styxlawyer.

Glett
11-10-2015, 06:36 PM
I will try it out on my real website now and let you's know how things go.

styxlawyer
11-10-2015, 06:38 PM
The first of those files is on the web, the second is on your local drive and the third might be anywhere.

How are you testing this? If it's on a local machine you will need to run a server (like XAMPP) on that machine so that the PHP interpreter will execute. However, if it's on a web server you will not be able to open a file on your own computer. Either way something isn't going to work.

Edited to add: Ah, too slow in typing. You have found that PHP doesn't run on your local machine unless you have an Apache server installed like XAMPP. It looks as though you are making progress.

Beverleyh
11-10-2015, 06:38 PM
even though they are the right file path

The 1st one should work.

The 2nd one wont work online because the path is local for your computer.

The 3rd one should again work, provided the 'Grace.pdf' file is in the same folder as the 'mystudies.php' page, and the letter-case matches (Unix systems are case-sensitive, Windows isnt)

You should check that your server is parsing the PHP - after clicking one of the links, view the page source to see what is printed in the iframe's src attribute. Each should look like this in turn;



<iframe src="https://onedrive.live.com/embed?cid=0912027297A21B07&resid=912027297A21B07%218989&authkey=AD_ol5nd3vdkIvY&em=2&wdStartOn=1&wdEmbedCode=0&wdPrint=0"></iframe>

<iframe src="C:\Users\ASUS\Documents\My Websites\HisCross\Hiscrosstester\Grace.pdf"></iframe>

<iframe src="Grace.pdf"></iframe>

Beverleyh
11-10-2015, 06:46 PM
The pdf's did not show up on the desktop side of things but when I uploaded it to my test website server , it worked just great , does php only function on the server side? and not on the client side (hope I am saying this stuff right)? Anyhow thanks alot Beverleyh and styxlawyer.Things are getting confusing because your replies are fragmented. Posting in quick succession might also lead you into bother with the spam filtering so try to keep your replies together in one post where possible.

Yes, PHP is a server-side language so it needs to run on a server. You can run one locally, such as WAMP (http://www.wampserver.com/en/) or XAMPP (https://www.apachefriends.org/index.html). Otherwise, upload to your web host (like you have) and it will work there.

Glett
11-12-2015, 04:47 AM
every thing is working good , on my web host , I might try this Xampp program , but now I need to work some other issues out , on my php page , which part of my website, is not showing as it should, though under my htnl page , it show up all good, but just need to work out hte bugs I guess. And with the Xampp program , can you view the php code, within Xampp , or just simply an editor which supports php ???

Beverleyh
11-12-2015, 06:38 AM
XAMPP is a local server. It acts like 'the web', but on your computer, and offers an environment in which to serve and execute php. It is not an editor so to see/edit the code in your web pages, you would open the pages in your preferred code/plain text editor, such as Notepad++ (or even plain/default Notepad in Windows). You're in the realms of *code* now, so it's unlikely that web *editors* (the visual drag + drop variety) will accept the file and allow you to *design* in it without destroying the php code inside.

Glett
11-12-2015, 03:07 PM
Thanks for all the info , the bugs have been worked out on my website, and maybe I will look into this php stuff further, I guess you could say that my issue has been resolved , thanks alot.